結果
問題 | No.281 門松と魔法(1) |
ユーザー | Grenache |
提出日時 | 2015-09-18 23:36:10 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 115 ms / 1,000 ms |
コード長 | 2,440 bytes |
コンパイル時間 | 4,378 ms |
コンパイル使用メモリ | 77,692 KB |
実行使用メモリ | 41,328 KB |
最終ジャッジ日時 | 2024-04-24 12:35:03 |
合計ジャッジ時間 | 10,518 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
40,880 KB |
testcase_01 | AC | 115 ms
41,184 KB |
testcase_02 | AC | 101 ms
39,960 KB |
testcase_03 | AC | 100 ms
40,036 KB |
testcase_04 | AC | 110 ms
41,008 KB |
testcase_05 | AC | 109 ms
41,048 KB |
testcase_06 | AC | 102 ms
40,816 KB |
testcase_07 | AC | 109 ms
40,904 KB |
testcase_08 | AC | 111 ms
41,228 KB |
testcase_09 | AC | 103 ms
39,984 KB |
testcase_10 | AC | 100 ms
39,824 KB |
testcase_11 | AC | 103 ms
40,792 KB |
testcase_12 | AC | 109 ms
41,224 KB |
testcase_13 | AC | 99 ms
40,876 KB |
testcase_14 | AC | 101 ms
39,912 KB |
testcase_15 | AC | 101 ms
40,176 KB |
testcase_16 | AC | 100 ms
41,048 KB |
testcase_17 | AC | 102 ms
41,064 KB |
testcase_18 | AC | 113 ms
41,076 KB |
testcase_19 | AC | 106 ms
41,128 KB |
testcase_20 | AC | 106 ms
41,072 KB |
testcase_21 | AC | 102 ms
41,120 KB |
testcase_22 | AC | 100 ms
41,060 KB |
testcase_23 | AC | 102 ms
40,156 KB |
testcase_24 | AC | 103 ms
40,912 KB |
testcase_25 | AC | 103 ms
40,044 KB |
testcase_26 | AC | 105 ms
40,608 KB |
testcase_27 | AC | 109 ms
41,320 KB |
testcase_28 | AC | 111 ms
41,104 KB |
testcase_29 | AC | 108 ms
40,044 KB |
testcase_30 | AC | 101 ms
40,392 KB |
testcase_31 | AC | 114 ms
41,236 KB |
testcase_32 | AC | 111 ms
40,844 KB |
testcase_33 | AC | 111 ms
40,972 KB |
testcase_34 | AC | 111 ms
40,956 KB |
testcase_35 | AC | 106 ms
40,936 KB |
testcase_36 | AC | 95 ms
39,732 KB |
testcase_37 | AC | 106 ms
40,844 KB |
testcase_38 | AC | 101 ms
40,740 KB |
testcase_39 | AC | 100 ms
40,144 KB |
testcase_40 | AC | 102 ms
40,968 KB |
testcase_41 | AC | 102 ms
41,328 KB |
testcase_42 | AC | 114 ms
41,192 KB |
testcase_43 | AC | 103 ms
40,044 KB |
testcase_44 | AC | 109 ms
41,152 KB |
testcase_45 | AC | 97 ms
39,720 KB |
testcase_46 | AC | 110 ms
41,060 KB |
testcase_47 | AC | 115 ms
41,200 KB |
testcase_48 | AC | 106 ms
39,968 KB |
testcase_49 | AC | 103 ms
40,972 KB |
testcase_50 | AC | 100 ms
39,864 KB |
testcase_51 | AC | 98 ms
39,828 KB |
testcase_52 | AC | 100 ms
39,980 KB |
testcase_53 | AC | 100 ms
39,992 KB |
testcase_54 | AC | 109 ms
41,124 KB |
testcase_55 | AC | 101 ms
39,720 KB |
testcase_56 | AC | 112 ms
41,172 KB |
ソースコード
import java.util.Scanner; public class Main_yukicoder281 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); int[] h = new int[3]; for (int i = 0; i < 3; i++) { h[i] = sc.nextInt(); } int min = Integer.MAX_VALUE; if (d == 0) { if (h[1] > h[0] && h[1] > h[2] && h[0] != h[2]) { min = 0; } else if (h[1] < h[0] && h[1] < h[2] && h[0] != h[2]) { min = 0; } } else { int[] a = new int[3]; int[] tmp = new int[3]; for (int i = 0; i < 3; i++) { tmp[i] = h[i]; } a[0] = 1; a[1] = 2; a[2] = 0; int tmp2 = getCnt(a, d, tmp); if (tmp2 != -1) { min = Math.min(min, tmp2); } for (int i = 0; i < 3; i++) { tmp[i] = h[i]; } a[0] = 1; a[1] = 0; a[2] = 2; tmp2 = getCnt(a, d, tmp); if (tmp2 != -1) { min = Math.min(min, tmp2); } for (int i = 0; i < 3; i++) { tmp[i] = h[i]; } a[0] = 0; a[1] = 2; a[2] = 1; tmp2 = getCnt(a, d, tmp); if (tmp2 != -1) { min = Math.min(min, tmp2); } for (int i = 0; i < 3; i++) { tmp[i] = h[i]; } a[0] = 2; a[1] = 0; a[2] = 1; tmp2 = getCnt(a, d, tmp); if (tmp2 != -1) { min = Math.min(min, tmp2); } } if (min == Integer.MAX_VALUE) { System.out.println("-1"); } else { System.out.println(min); } sc.close(); } private static int getCnt(int[] a,int d, int[] h) { int tmp = 0; if (h[a[0]] == 0) { return -1; } if (h[a[0]] == h[a[1]]) { h[a[1]] = Math.max(0, h[a[1]] - d); tmp += 1; } else if (h[a[0]] < h[a[1]]) { int tmp2 = (h[a[1]] - h[a[0]] + d) / d; h[a[1]] = Math.max(0, h[a[1]] - tmp2 * d); tmp += tmp2; } if (h[a[1]] == 0) { return -1; } if (h[a[1]] == h[a[2]]) { h[a[2]] = Math.max(0, h[a[2]] - d); tmp += 1; } else if (h[a[1]] < h[a[2]]) { int tmp2 = (h[a[2]] - h[a[1]] + d) / d; h[a[2]] = Math.max(0, h[a[2]] - tmp2 * d); tmp += tmp2; } return tmp; } }