Submission #3606792
Source Code Expand
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
ll H, W;
int main() {
cin.tie(0);
cin >> H >> W;
ll ans = INF;
rep(d, 1, H-1) {
ll ps = W * d;
ll t = (H-d) / 2;
ll qff = W * t, qfs = W * ((H-d) - t);
ll mi = min({ps, qff, qfs}), ma = max({ps, qff, qfs});
ans = min(ans, ma - mi);
ll qsf = (H-d) * (W/2), qss = (H-d) * (W - W/2);
mi = min({ps, qsf, qss}), ma = max({ps, qsf, qss});
ans = min(ans, ma - mi);
}
swap(H, W);
rep(d, 1, H-1) {
ll ps = W * d;
ll t = (H-d) / 2;
ll qff = W * t, qfs = W * ((H-d) - t);
ll mi = min({ps, qff, qfs}), ma = max({ps, qff, qfs});
ans = min(ans, ma - mi);
ll qsf = (H-d) * (W/2), qss = (H-d) * (W - W/2);
mi = min({ps, qsf, qss}), ma = max({ps, qsf, qss});
ans = min(ans, ma - mi);
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Chocolate Bar |
User |
kage |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1883 Byte |
Status |
WA |
Exec Time |
2 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
WA |
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 |
2 ms |
256 KB |