結果
問題 | No.4 おもりと天秤 |
ユーザー | DAZY |
提出日時 | 2017-05-23 01:57:13 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,041 bytes |
コンパイル時間 | 5,866 ms |
コンパイル使用メモリ | 78,340 KB |
実行使用メモリ | 62,092 KB |
最終ジャッジ日時 | 2023-10-19 14:28:49 |
合計ジャッジ時間 | 13,950 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 138 ms
57,080 KB |
testcase_01 | AC | 144 ms
55,248 KB |
testcase_02 | AC | 143 ms
57,148 KB |
testcase_03 | AC | 137 ms
57,104 KB |
testcase_04 | AC | 146 ms
57,284 KB |
testcase_05 | AC | 149 ms
57,716 KB |
testcase_06 | AC | 135 ms
57,516 KB |
testcase_07 | AC | 144 ms
57,740 KB |
testcase_08 | AC | 151 ms
57,940 KB |
testcase_09 | AC | 149 ms
57,716 KB |
testcase_10 | AC | 149 ms
57,508 KB |
testcase_11 | AC | 142 ms
57,304 KB |
testcase_12 | AC | 140 ms
57,472 KB |
testcase_13 | AC | 140 ms
57,304 KB |
testcase_14 | AC | 137 ms
57,736 KB |
testcase_15 | AC | 138 ms
57,576 KB |
testcase_16 | AC | 139 ms
57,320 KB |
testcase_17 | AC | 132 ms
57,684 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
import java.util.Scanner; public class No4 { public static boolean check (int half, int[] W, int i, boolean b) { int tmp; i--; for (; i >= 0; i--) { if (b) break; tmp = half - W[i]; if (tmp >= 0) { if (tmp == 0) b = true; else b = check(tmp, W, i, b); } } return b; } public static void main (String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int W[] = new int[N]; int sum = 0; int half; boolean b = false; for (int i = 0; i < N; i++) { W[i] = scan.nextInt(); sum += W[i]; } //合計が奇数なら2等分することはできない if (sum % 2 != 0) { System.out.println("impossible"); System.exit(0); } half = sum/2; if (check(half, W, N, b)) System.out.println("possible"); else System.out.println("impossible"); } }