Submission #1297111


Source Code Expand

Copy
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 100000000
using namespace std;

long H, W;
long s, r;

int main(void) {
  cin >> H >> W;

  long ans = INF;

  REP(i, 1, H) {
    long p1 = i * W;
    long p2 = (H - i) * (W / 2);
    long p3 = H * W - p1 - p2;
    long d = max(p1, max(p2, p3)) - min(p1, min(p2, p3));
    ans = min(ans, d);

    long q1 = i * W;
    long q2 = ((H - i) / 2) * W;
    long q3 = H * W - q1 - q2;
    long e = max(q1, max(q2, q3)) - min(q1, min(q2, q3));
    ans = min(ans, e);
  }

  REP(i, 1, W) {
    long p1 = i * H;
    long p2 = (W - i) * (H / 2);
    long p3 = H * W - p1 - p2;
    long d = max(p1, max(p2, p3)) - min(p1, min(p2, p3));
    ans = min(ans, d);

    long q1 = i * H;
    long q2 = ((W - i) / 2) * H;
    long q3 = H * W - q1 - q2;
    long e = max(q1, max(q2, q3)) - min(q1, min(q2, q3));
    ans = min(ans, e);
  }

  cout << ans << endl;

  return 0;
}

Submission Info

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

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 400 / 400 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 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 2 ms 256 KB
0_04.txt 2 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 2 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 2 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 2 ms 256 KB
1_06.txt 2 ms 256 KB
1_07.txt 2 ms 256 KB
1_08.txt 2 ms 256 KB
1_09.txt 2 ms 256 KB
1_10.txt 2 ms 256 KB
1_11.txt 1 ms 256 KB
1_12.txt 2 ms 256 KB
1_13.txt 2 ms 256 KB
1_14.txt 1 ms 256 KB