結果
問題 | No.4 おもりと天秤 |
ユーザー | kuramu |
提出日時 | 2016-01-20 15:57:52 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,182 bytes |
コンパイル時間 | 1,798 ms |
コンパイル使用メモリ | 77,924 KB |
実行使用メモリ | 53,860 KB |
最終ジャッジ日時 | 2023-10-21 13:32:19 |
合計ジャッジ時間 | 3,703 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge10 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
52,452 KB |
testcase_01 | AC | 47 ms
52,304 KB |
testcase_02 | AC | 48 ms
53,588 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | WA | - |
testcase_08 | AC | 48 ms
53,440 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 48 ms
53,584 KB |
testcase_12 | RE | - |
testcase_13 | AC | 48 ms
53,580 KB |
testcase_14 | AC | 46 ms
53,580 KB |
testcase_15 | AC | 47 ms
52,488 KB |
testcase_16 | AC | 48 ms
53,588 KB |
testcase_17 | AC | 48 ms
51,660 KB |
testcase_18 | AC | 47 ms
53,576 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { int N = Integer.parseInt(stdReader.readLine()); String[] temps = stdReader.readLine().split(" "); int[] nums = new int[N+1]; int sum = 0; for(int i=0;i<N;i++){ nums[i+1] = Integer.parseInt(temps[i]); sum += nums[i+1]; } if(sum%2 != 0){ System.out.println("impossible"); return; } Arrays.sort(nums); int half = sum/2; boolean[] dp = new boolean[half+1]; dp[nums[1]] = true; for(int i=2;i<nums.length;i++){ dp[nums[i]] = true; for(int j=1;j<half+1;j++){ if(j > nums[i]) break; if(dp[j] && j+nums[i] <= half) dp[j+nums[i]] = true; } } if(dp[half]) System.out.println("possible"); else System.out.println("impossible"); } catch (IOException e) { e.printStackTrace(); } } }