Submission #2104864
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
/*
<url:https://arc074.contest.atcoder.jp/tasks/arc074_a>
問題文============================================================
縦 H ブロック、横 W ブロックの板チョコがあります。
すぬけ君は、この板チョコをちょうど 3 つのピースに分割しようとしています。
ただし、各ピースはブロックの境目に沿った長方形でなければなりません。
すぬけ君は、3 つのピースの面積 (ブロック数) をできるだけ均等にしようとしています。
具体的には、3 つのピースの面積の最大値を Smax、最小値を Smin としたとき、
Smax−Smin を最小化しようとしています。 Smax−Smin の最小値を求めてください。
=================================================================
解説=============================================================
================================================================
*/
int main(void) {
cin.tie(0); ios::sync_with_stdio(false);
ll H,W; cin >> H >> W;
ll ans = LINF;
/*
パターン1
サンプル1のようなパターン
*/
for(int i = 1; i <= H - 2;i++){
ll S1 = i*W;
ll S2 = ((H - i)/2) * W;
ll S3 = ((H - i) - (H - i)/2)*W;
ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
}
/*
パターン2
パターン1を90度回転させたパターン
*/
for(int i = 1; i <= W - 2;i++){
ll S1 = i*H;
ll S2 = ((W - i)/2) * H;
ll S3 = ((W - i) - (W - i)/2)*H;
ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
}
/*
パターン3
サンプル2のようなパターン
*/
for(int i = 1; i <= W;i++){
ll S1 = H*i;
ll S2 = (H/2)*(W-i);
ll S3 = (H - H/2)*(W-i);
ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
}
/*
パターン4
パターン3を90度回転させたパターン(サンプル3のようなパターン)
*/
for(int i = 1; i <= H; i++){
ll S1 = W*i;
ll S2 = (W/2)*(H-i);
ll S3 = (W - W/2)*(H-i);
ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Chocolate Bar |
User |
clavis1107 |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
2491 Byte |
Status |
AC |
Exec Time |
2 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
0_03.txt |
AC |
2 ms |
256 KB |
0_04.txt |
AC |
2 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
2 ms |
256 KB |
1_02.txt |
AC |
2 ms |
256 KB |
1_03.txt |
AC |
2 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
AC |
2 ms |
256 KB |
1_06.txt |
AC |
2 ms |
256 KB |
1_07.txt |
AC |
2 ms |
256 KB |
1_08.txt |
AC |
2 ms |
256 KB |
1_09.txt |
AC |
2 ms |
256 KB |
1_10.txt |
AC |
2 ms |
256 KB |
1_11.txt |
AC |
2 ms |
256 KB |
1_12.txt |
AC |
2 ms |
256 KB |
1_13.txt |
AC |
2 ms |
256 KB |
1_14.txt |
AC |
1 ms |
256 KB |