Submission #3772820
Source Code Expand
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define INF (1000000000)
using namespace std;
int main(int argc, char *argv[]) {
// read inputs
long H, W;
scanf("%ld %ld", &H, &W);
// there are only four patterns of cutting
// ||
long diff1 = W % 3 == 0 ? 0 : H;
// -
// -
long diff2 = H % 3 == 0 ? 0 : W;
// |-
long diff3 = INF;
const long h3_1 = H / 2, h3_2 = H - h3_1;
for (int j = 1; j <= W; j++) {
const long S1 = H * j, S2 = h3_1 * (W - j), S3 = h3_2 * (W - j);
diff3 = min(diff3, max(max(abs(S1 - S2), abs(S2 - S3)), abs(S3 - S1)));
}
// |
// -
long diff4 = INF;
const long w4_1 = W / 2, w4_2 = W - w4_1;
for (int i = 1; i <= H; i++) {
const long S1 = i * W, S2 = (H - i) * w4_1, S3 = (H - i) * w4_2;
diff4 = min(diff4, max(max(abs(S1 - S2), abs(S2 - S3)), abs(S3 - S1)));
}
// print ans
printf("%ld\n", min(diff1, min(diff2, min(diff3, diff4))));
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Chocolate Bar |
User |
khir |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
989 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
128 KB |
Compile Error
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:12:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%ld %ld", &H, &W);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 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 |
128 KB |
0_01.txt |
AC |
1 ms |
128 KB |
0_02.txt |
AC |
1 ms |
128 KB |
0_03.txt |
AC |
1 ms |
128 KB |
0_04.txt |
AC |
1 ms |
128 KB |
1_00.txt |
AC |
1 ms |
128 KB |
1_01.txt |
AC |
1 ms |
128 KB |
1_02.txt |
AC |
1 ms |
128 KB |
1_03.txt |
AC |
1 ms |
128 KB |
1_04.txt |
AC |
1 ms |
128 KB |
1_05.txt |
AC |
1 ms |
128 KB |
1_06.txt |
AC |
1 ms |
128 KB |
1_07.txt |
AC |
1 ms |
128 KB |
1_08.txt |
AC |
1 ms |
128 KB |
1_09.txt |
AC |
1 ms |
128 KB |
1_10.txt |
AC |
1 ms |
128 KB |
1_11.txt |
AC |
1 ms |
128 KB |
1_12.txt |
AC |
1 ms |
128 KB |
1_13.txt |
AC |
1 ms |
128 KB |
1_14.txt |
AC |
1 ms |
128 KB |