Submission #2104761


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc074.contest.atcoder.jp/tasks/arc074_a>
問題文============================================================
 縦 H ブロック、横 W ブロックの板チョコがあります。
 すぬけ君は、この板チョコをちょうど 3 つのピースに分割しようとしています。
 ただし、各ピースはブロックの境目に沿った長方形でなければなりません。
 
 すぬけ君は、3 つのピースの面積 (ブロック数) をできるだけ均等にしようとしています。
 具体的には、3 つのピースの面積の最大値を Smax、最小値を Smin としたとき、
 Smax−Smin を最小化しようとしています。 Smax−Smin の最小値を求めてください。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    if(H%3 == 0 || W%3 == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = LINF;
    for(int i = 1; i <= W;i++){
        ll S1 = H*i;
        ll S2 = (H/2)*(W-i);
        ll S3 = (H - H/2)*(W-i);
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    for(int i = 1; i <= H; i++){
        ll S1 = W*i;
        ll S2 = (W/2)*(H-i);
        ll S3 = (W - W/2)*(H-i);
        ans = min(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
    }
    cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Chocolate Bar
User clavis1107
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1755 Byte
Status WA
Exec Time 2 ms
Memory 256 KB

Judge Result

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