Submission #2095999


Source Code Expand

// ARC074-C
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll f(ll h, ll w) {
   ll Min = 1e18;
   for (ll i = 1; i < w; i++) {
      ll j = w - i;

      ll left = i * h;
      // 縦3分割
      ll a = j/2, b = j - a;
      ll mid = a * h, right = b * h;
      ll v[] = {left, mid, right};
      sort(v, v+3);
      Min = min(Min, v[2] - v[0]);

      // 縦2、横2
      a = h/2, b = h - a;
      ll up = a * j, un = b * j;
      ll t[] = {left, up, un};
      sort(t, t+3);
      Min = min(Min, t[2] - t[0]);
   }
   return Min;
}

int main() {
   ll H, W;
   cin >> H >> W;

   cout << min(f(H, W), f(W, H)) << endl;

   return 0;
}

Submission Info

Submission Time
Task C - Chocolate Bar
User nomi
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1685 Byte
Status AC
Exec Time 6 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 4 ms 256 KB
0_04.txt AC 6 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 4 ms 256 KB
1_02.txt AC 3 ms 256 KB
1_03.txt AC 4 ms 256 KB
1_04.txt AC 3 ms 256 KB
1_05.txt AC 4 ms 256 KB
1_06.txt AC 6 ms 256 KB
1_07.txt AC 4 ms 256 KB
1_08.txt AC 4 ms 256 KB
1_09.txt AC 4 ms 256 KB
1_10.txt AC 5 ms 256 KB
1_11.txt AC 3 ms 256 KB
1_12.txt AC 5 ms 256 KB
1_13.txt AC 4 ms 256 KB
1_14.txt AC 3 ms 256 KB