結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
mosmos_21
|
| 提出日時 | 2017-06-17 11:57:39 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,076 bytes |
| コンパイル時間 | 2,184 ms |
| コンパイル使用メモリ | 77,120 KB |
| 実行使用メモリ | 56,020 KB |
| 最終ジャッジ日時 | 2024-10-01 09:30:01 |
| 合計ジャッジ時間 | 6,214 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 12 |
ソースコード
import java.util.Scanner;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
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 == 1) {
System.out.println("impossible");
return;
}
int h = sum / 2;
boolean[][] dp = new boolean[h + 1][N];
for (int i = 0; i < dp.length; i++) {
dp[i][0] = true;
}
for (int i = 0; i < dp[0].length; i++) {
dp[0][i] = true;
}
for (int i = 0; i < dp.length; i++) {
for (int j = 0; j < dp[0].length; j++) {
if (dp[i][j] && i + w[j] <= h) {
dp[i + w[j]][j] = true;
}
}
}
if (dp[h][N - 1])
{
System.out.println("possible");
} else {
System.out.println("impossible");
}
}
}
mosmos_21