結果
問題 | No.4 おもりと天秤 |
ユーザー | spacia |
提出日時 | 2015-12-19 11:01:11 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 958 bytes |
コンパイル時間 | 1,886 ms |
コンパイル使用メモリ | 74,120 KB |
実行使用メモリ | 50,728 KB |
最終ジャッジ日時 | 2023-10-14 14:16:25 |
合計ジャッジ時間 | 3,892 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,624 KB |
testcase_01 | AC | 41 ms
49,428 KB |
testcase_02 | AC | 41 ms
49,364 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 44 ms
49,296 KB |
testcase_07 | WA | - |
testcase_08 | AC | 43 ms
49,424 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 43 ms
49,244 KB |
testcase_12 | AC | 43 ms
49,848 KB |
testcase_13 | AC | 43 ms
49,824 KB |
testcase_14 | AC | 43 ms
49,404 KB |
testcase_15 | AC | 42 ms
49,628 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 49 ms
49,412 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
import java.io.*; import java.util.*; class Main4 { public static boolean check (int[] nums, int target) { boolean[] dp = new boolean[target + 1]; Arrays.sort(nums); dp[0] = true; for (int i = 0; i < nums.length; i++) { for (int j = 0; j <= target; j++) { if (!dp[j]) continue; if (nums[i] + j <= target) dp[j = nums[i] + j] = true; else break; } } return dp[target]; } public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int target = 0; int[] nums = new int[n]; String[] str = br.readLine().split(" "); for (int i = 0; i < n; i++) { nums[i] = Integer.parseInt(str[i]); target += nums[i]; } if (target % 2 == 1) System.out.println("impossible"); else { target /= 2; System.out.println(check(nums, target) ? "possible" : "impossible"); } } }