Submission #5950102
Source Code Expand
/*{{{*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
ll h,w;
cin >> h >> w;
if(h%3==0 || w%3==0){
cout << 0 << endl;
return 0;
}
ll ans = 1e9;
// horizontal
CHMIN(ans,w);
// vertical
CHMIN(ans,h);
ll sh = h/3;
CHMIN(ans,max(abs((h-sh)*(w%2)),max(abs(sh*w-(h-sh)*(w/2)),abs(sh*w-(h-sh)*(w-w/2)))));
sh++;
CHMIN(ans,max(abs((h-sh)*(w%2)),max(abs(sh*w-(h-sh)*(w/2)),abs(sh*w-(h-sh)*(w-w/2)))));
ll sw = w/3;
CHMIN(ans,max(abs((w-sw)*(h%2)),max(abs(sw*h-(w-sw)*(h/2)),abs(sw*h-(w-sw)*(h-h/2)))));
sw++;
CHMIN(ans,max(abs((w-sw)*(h%2)),max(abs(sw*h-(w-sw)*(h/2)),abs(sw*h-(w-sw)*(h-h/2)))));
cout << ans<< endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Chocolate Bar |
User |
Namazu |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
1282 Byte |
Status |
AC |
Exec Time |
7 ms |
Memory |
764 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 |
7 ms |
764 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
0_03.txt |
AC |
1 ms |
256 KB |
0_04.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
1 ms |
256 KB |
1_03.txt |
AC |
1 ms |
256 KB |
1_04.txt |
AC |
1 ms |
256 KB |
1_05.txt |
AC |
1 ms |
256 KB |
1_06.txt |
AC |
1 ms |
256 KB |
1_07.txt |
AC |
1 ms |
256 KB |
1_08.txt |
AC |
1 ms |
256 KB |
1_09.txt |
AC |
1 ms |
256 KB |
1_10.txt |
AC |
1 ms |
256 KB |
1_11.txt |
AC |
1 ms |
256 KB |
1_12.txt |
AC |
1 ms |
256 KB |
1_13.txt |
AC |
1 ms |
256 KB |
1_14.txt |
AC |
1 ms |
256 KB |