Last active
June 27, 2018 14:49
-
-
Save sadmiko/6d86b1a3d5331fc5f9ce2fa74456d865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
long long int h,w,a,b; | |
long long int ans,M,m,X,Y,Z; | |
cin>>h>>w; | |
if(h*w%3==0){ | |
cout<<0<<endl; | |
return 0; | |
} | |
ans=min(h,w); | |
for(int k=0;k<2;++k){ | |
for(int i=0;i<=1;++i){ | |
for(int j=0;j<=1;++j){ | |
a=w/3+i;b=h/2+j; | |
X=a*h; | |
Y=b*(w-a); | |
Z=(w-a)*(h-b); | |
M=max(X,Y); | |
M=max(M,Z); | |
m=min(X,Y); | |
m=min(m,Z); | |
ans=min(ans,M-m); | |
} | |
} | |
swap(h,w); | |
} | |
cout<<ans<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment