Submission #2127621
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 1e9 //
#define INFLL 4e18 //
#define MOD (1e9)+7
#define MP make_pair
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
// a 0x61 z 0x7a 0 0x30
//------------------------------------------------------
pll two_cut(ll x, ll y) { //横に切る
if (y % 2 == 0) {
return (MP(y / 2 * x, y / 2 * x));
} else {
return (MP((y / 2 + 1) * x, y / 2 * x));
}
}
int main() {
ll H, W;
cin >> H >> W;
ll s, smm;
ll sout = INFLL;
rep2(i, H - 1) {
s = i * W;
pll p = two_cut(W, H - i);
smm = max({s, p.first, p.second}) - min({s, p.first, p.second});
sout = min(sout, smm);
}
rep2(i, W - 1) {
s = H * i;
pll p = two_cut(W - i, H);
smm = max({s, p.first, p.second}) - min({s, p.first, p.second});
sout = min(sout, smm);
}
swap(H, W);
rep2(i, H - 1) {
s = i * W;
pll p = two_cut(W, H - i);
smm = max({s, p.first, p.second}) - min({s, p.first, p.second});
sout = min(sout, smm);
}
rep2(i, W - 1) {
s = H * i;
pll p = two_cut(W - i, H);
smm = max({s, p.first, p.second}) - min({s, p.first, p.second});
sout = min(sout, smm);
}
cout << sout << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Chocolate Bar |
User |
stoq |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1617 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 |
2 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 |