結果
問題 | No.281 門松と魔法(1) |
ユーザー | Grenache |
提出日時 | 2015-09-18 23:36:10 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 144 ms / 1,000 ms |
コード長 | 2,440 bytes |
コンパイル時間 | 3,921 ms |
コンパイル使用メモリ | 77,828 KB |
実行使用メモリ | 54,484 KB |
最終ジャッジ日時 | 2024-11-06 20:28:30 |
合計ジャッジ時間 | 13,423 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
54,020 KB |
testcase_01 | AC | 136 ms
54,140 KB |
testcase_02 | AC | 134 ms
54,112 KB |
testcase_03 | AC | 135 ms
53,960 KB |
testcase_04 | AC | 136 ms
53,852 KB |
testcase_05 | AC | 137 ms
54,096 KB |
testcase_06 | AC | 136 ms
54,212 KB |
testcase_07 | AC | 136 ms
54,084 KB |
testcase_08 | AC | 137 ms
53,872 KB |
testcase_09 | AC | 139 ms
54,056 KB |
testcase_10 | AC | 144 ms
54,088 KB |
testcase_11 | AC | 135 ms
54,068 KB |
testcase_12 | AC | 137 ms
54,196 KB |
testcase_13 | AC | 137 ms
54,252 KB |
testcase_14 | AC | 134 ms
54,164 KB |
testcase_15 | AC | 137 ms
54,164 KB |
testcase_16 | AC | 136 ms
54,208 KB |
testcase_17 | AC | 133 ms
53,860 KB |
testcase_18 | AC | 138 ms
54,088 KB |
testcase_19 | AC | 137 ms
54,372 KB |
testcase_20 | AC | 139 ms
54,052 KB |
testcase_21 | AC | 136 ms
54,040 KB |
testcase_22 | AC | 136 ms
53,992 KB |
testcase_23 | AC | 135 ms
54,412 KB |
testcase_24 | AC | 135 ms
54,248 KB |
testcase_25 | AC | 136 ms
54,096 KB |
testcase_26 | AC | 136 ms
53,840 KB |
testcase_27 | AC | 134 ms
54,284 KB |
testcase_28 | AC | 136 ms
54,148 KB |
testcase_29 | AC | 133 ms
54,208 KB |
testcase_30 | AC | 137 ms
53,908 KB |
testcase_31 | AC | 135 ms
54,060 KB |
testcase_32 | AC | 136 ms
53,904 KB |
testcase_33 | AC | 135 ms
54,152 KB |
testcase_34 | AC | 134 ms
54,240 KB |
testcase_35 | AC | 136 ms
54,100 KB |
testcase_36 | AC | 134 ms
54,484 KB |
testcase_37 | AC | 135 ms
54,084 KB |
testcase_38 | AC | 136 ms
54,020 KB |
testcase_39 | AC | 133 ms
54,224 KB |
testcase_40 | AC | 135 ms
54,108 KB |
testcase_41 | AC | 135 ms
53,820 KB |
testcase_42 | AC | 139 ms
54,056 KB |
testcase_43 | AC | 137 ms
54,088 KB |
testcase_44 | AC | 136 ms
54,136 KB |
testcase_45 | AC | 137 ms
54,316 KB |
testcase_46 | AC | 135 ms
54,184 KB |
testcase_47 | AC | 138 ms
54,320 KB |
testcase_48 | AC | 133 ms
54,228 KB |
testcase_49 | AC | 134 ms
54,024 KB |
testcase_50 | AC | 133 ms
54,196 KB |
testcase_51 | AC | 137 ms
53,840 KB |
testcase_52 | AC | 132 ms
54,000 KB |
testcase_53 | AC | 134 ms
54,140 KB |
testcase_54 | AC | 138 ms
54,148 KB |
testcase_55 | AC | 134 ms
53,948 KB |
testcase_56 | AC | 134 ms
53,924 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; } }