Submission #1301335
Source Code Expand
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
long h = cin.nextLong();
long w = cin.nextLong();
long ans = Math.min(func1(h, w), func2(h, w));
ans = Math.min(ans, func2(w, h));
System.out.println(ans);
}
public static long func1(long h, long w){
if(h % 3 == 0 || w % 3 == 0){
return 0;
}
return Math.min(h, w);
}
public static long func2(long h, long w){
long min_dif = h * w ;
if(w % 2 == 0) {
for (long i = 1; i < h; ++i ) {
min_dif = Math.min(Math.abs(w * i - w / 2 * (h - i)), min_dif );
}
} else {
for (long i = 1; i < h; ++i ) {
long max_dif = Math.max(Math.abs( (w+1) / 2 * (h - i) - w / 2 * (h - i)) , Math.max(Math.abs(w * i - w / 2 * (h - i)), Math.abs(w * i - (w+1) / 2 * (h - i))));
min_dif = Math.min(max_dif, min_dif);
}
}
return min_dif;
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Chocolate Bar |
| User | take1223xxx |
| Language | Java8 (OpenJDK 1.8.0) |
| Score | 400 |
| Code Size | 933 Byte |
| Status | AC |
| Exec Time | 130 ms |
| Memory | 24020 KiB |
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 | 100 ms | 21844 KiB |
| 0_01.txt | AC | 100 ms | 21460 KiB |
| 0_02.txt | AC | 98 ms | 21460 KiB |
| 0_03.txt | AC | 104 ms | 19796 KiB |
| 0_04.txt | AC | 110 ms | 18640 KiB |
| 1_00.txt | AC | 98 ms | 21332 KiB |
| 1_01.txt | AC | 106 ms | 21204 KiB |
| 1_02.txt | AC | 112 ms | 21332 KiB |
| 1_03.txt | AC | 118 ms | 21588 KiB |
| 1_04.txt | AC | 115 ms | 20560 KiB |
| 1_05.txt | AC | 130 ms | 21460 KiB |
| 1_06.txt | AC | 117 ms | 18772 KiB |
| 1_07.txt | AC | 103 ms | 21844 KiB |
| 1_08.txt | AC | 107 ms | 21460 KiB |
| 1_09.txt | AC | 121 ms | 24020 KiB |
| 1_10.txt | AC | 122 ms | 21460 KiB |
| 1_11.txt | AC | 104 ms | 21588 KiB |
| 1_12.txt | AC | 121 ms | 19668 KiB |
| 1_13.txt | AC | 107 ms | 21716 KiB |
| 1_14.txt | AC | 103 ms | 21844 KiB |