結果

問題 No.4 おもりと天秤
ユーザー ぴろずぴろず
提出日時 2014-12-21 00:58:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 654 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 74,132 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-09-02 20:29:03
合計ジャッジ時間 6,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,552 KB
testcase_01 AC 123 ms
56,120 KB
testcase_02 WA -
testcase_03 AC 122 ms
56,376 KB
testcase_04 AC 122 ms
56,136 KB
testcase_05 AC 141 ms
55,700 KB
testcase_06 WA -
testcase_07 AC 141 ms
55,852 KB
testcase_08 AC 131 ms
55,932 KB
testcase_09 AC 142 ms
55,908 KB
testcase_10 AC 142 ms
55,732 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 123 ms
56,036 KB
testcase_17 AC 122 ms
56,212 KB
testcase_18 WA -
testcase_19 AC 141 ms
55,728 KB
testcase_20 AC 142 ms
56,304 KB
testcase_21 AC 142 ms
55,896 KB
testcase_22 AC 143 ms
55,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no004;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		int sum = 0;
		for(int i=0;i<n;i++) {
			w[i] = sc.nextInt();
			sum += w[i];
		}
		if (sum % 2 == 1) {
			System.out.println("impossible");
			return;
		}
		sum /= 2;
		boolean[][] dp = new boolean[n+1][sum+1];
		dp[0][0] = true;
		for(int i=1;i<=n;i++) {
			for(int j=0;j<=sum;j++) {
				dp[i][j] = dp[i-1][j];
				if (j - w[i-1] >= 0) {
					dp[i][j] |= dp[i-1][j-w[i-1]];
				}
			}
		}
		System.out.println(dp[n][sum] ? "possible" : "impossoble");
	}

}
0