結果
問題 | No.4 おもりと天秤 |
ユーザー | actu3 |
提出日時 | 2015-06-20 16:53:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 97 ms / 5,000 ms |
コード長 | 2,048 bytes |
コンパイル時間 | 3,495 ms |
コンパイル使用メモリ | 77,880 KB |
実行使用メモリ | 51,720 KB |
最終ジャッジ日時 | 2024-06-26 09:14:03 |
合計ジャッジ時間 | 5,942 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
50,256 KB |
testcase_01 | AC | 57 ms
50,512 KB |
testcase_02 | AC | 61 ms
49,944 KB |
testcase_03 | AC | 59 ms
50,252 KB |
testcase_04 | AC | 59 ms
50,496 KB |
testcase_05 | AC | 94 ms
51,532 KB |
testcase_06 | AC | 55 ms
50,316 KB |
testcase_07 | AC | 92 ms
51,456 KB |
testcase_08 | AC | 55 ms
49,824 KB |
testcase_09 | AC | 93 ms
51,720 KB |
testcase_10 | AC | 94 ms
51,404 KB |
testcase_11 | AC | 57 ms
49,948 KB |
testcase_12 | AC | 57 ms
49,976 KB |
testcase_13 | AC | 56 ms
50,172 KB |
testcase_14 | AC | 56 ms
50,292 KB |
testcase_15 | AC | 56 ms
50,404 KB |
testcase_16 | AC | 58 ms
50,248 KB |
testcase_17 | AC | 56 ms
50,400 KB |
testcase_18 | AC | 93 ms
51,568 KB |
testcase_19 | AC | 97 ms
51,440 KB |
testcase_20 | AC | 94 ms
51,328 KB |
testcase_21 | AC | 93 ms
51,232 KB |
testcase_22 | AC | 92 ms
51,648 KB |
ソースコード
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; public class Yuki4 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] w = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { w[i] = in.nextInt(); sum += w[i]; } if (sum % 2 != 0) { System.out.println("impossible"); return; } final int MAX = 10001; boolean[] possible = new boolean[MAX]; possible[0] = true; for (int i = 0; i < n; i++) { boolean[] np = new boolean[MAX]; for (int j = 0; j < MAX; j++) { np[j] = possible[j]; } for (int j = 0; j < MAX; j++) { if (!possible[j]) continue; int next = j + w[i]; np[next] = true; } possible = np; } String ans = possible[sum/2] ? "possible" : "impossible"; System.out.println(ans); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }