Submission #1691852


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
ll n,m,v,i,h,w;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>h>>w;
  ll ans = INF;
  if(h%3==0||w%3==0){
    cout<<0<<endl;
    return;
  } else {
    minch(ans,w);
    minch(ans,h);
  }

  repl(i,1,h/2+1){
    ll Smax = 0,Smin = INF;
    if(w%2==0){
      Smax = max(w*i,(h-i)*(w/2));
      Smin = min(w*i,(h-i)*(w/2));
    } else {
      Smax = max(w*i,(h-i)*(w/2+1));
      Smin = min(w*i,(h-i)*(w/2));
    }
    minch(ans,Smax-Smin);
  }
  repl(i,1,w/2+1){
    ll Smax = 0,Smin = INF;
    if(h%2==0){
      Smax = max(h*i,(w-i)*(h/2));
      Smin = min(h*i,(w-i)*(h/2));
    } else {
      Smax = max(h*i,(w-i)*(h/2+1));
      Smin = min(h*i,(w-i)*(h/2));
    }
    minch(ans,Smax-Smin);
  }
  cout<<ans<<endl;

}

int main(){
  solve();
  return 0;
}

Submission Info

Submission Time
Task C - Chocolate Bar
User koki1018
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1740 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 20
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 1 ms 256 KB
0_04.txt AC 2 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