結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-05-07 23:10:41 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,464 bytes |
コンパイル時間 | 2,109 ms |
コンパイル使用メモリ | 77,676 KB |
実行使用メモリ | 38,000 KB |
最終ジャッジ日時 | 2024-09-14 14:53:30 |
合計ジャッジ時間 | 4,177 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 WA * 21 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.stream.Stream; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int N = Integer.parseInt(reader.readLine()); String[] inputs = reader.readLine().split(" "); int[] weights = new int[N]; int sumOfWeights = 0; for (int i = 0; i < N; i++) { int weight = Integer.parseInt(inputs[i]); weights[i] = weight; sumOfWeights += weight; } if (sumOfWeights % 2 != 0) { System.out.println("impossible"); } else { int requiredWeight = sumOfWeights / 2; boolean[][] dp = new boolean[101][10001]; dp[0][0] = true; for (int i = 0; i < N; i++) { for (int j = 0; j <= 10; j++) { if (dp[i][j]) { dp[i + 1][j + weights[i]] = true; dp[i + 1][j] = true; } } } System.out.println(Arrays.toString(dp)); if (dp[N][requiredWeight]) { System.out.println("possible"); } else { System.out.println("impossible"); } } } }