結果

問題 No.4 おもりと天秤
ユーザー YamaKasaYamaKasa
提出日時 2018-10-07 15:14:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 77,804 KB
実行使用メモリ 59,356 KB
最終ジャッジ日時 2024-04-20 18:14:35
合計ジャッジ時間 6,008 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
53,056 KB
testcase_01 AC 112 ms
52,912 KB
testcase_02 AC 118 ms
53,636 KB
testcase_03 AC 121 ms
54,112 KB
testcase_04 AC 128 ms
54,288 KB
testcase_05 AC 143 ms
58,932 KB
testcase_06 AC 108 ms
53,112 KB
testcase_07 AC 140 ms
59,056 KB
testcase_08 AC 129 ms
54,500 KB
testcase_09 AC 142 ms
58,948 KB
testcase_10 AC 144 ms
58,984 KB
testcase_11 AC 124 ms
54,156 KB
testcase_12 AC 118 ms
53,940 KB
testcase_13 AC 118 ms
54,412 KB
testcase_14 AC 107 ms
53,152 KB
testcase_15 AC 111 ms
53,616 KB
testcase_16 AC 111 ms
52,940 KB
testcase_17 AC 119 ms
54,360 KB
testcase_18 AC 141 ms
59,100 KB
testcase_19 AC 137 ms
58,796 KB
testcase_20 AC 142 ms
58,788 KB
testcase_21 AC 146 ms
59,356 KB
testcase_22 AC 143 ms
58,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[]W = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++) {
			W[i] = scan.nextInt();
			sum += W[i];
		}
		scan.close();
		if(sum % 2 == 1) {
			System.out.println("impossible");
			System.exit(0);
		}

		int[][]dp = new int[N + 1][10001];
		dp[0][0] = 1;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j <= 10000; j++) {
				if(dp[i][j] == 1) {
					dp[i + 1][j + W[i]] = 1;
					dp[i + 1][j] = 1;
				}
			}
		}
		if(dp[N][sum / 2] == 1) {
			System.out.println("possible");
		}else {
			System.out.println("impossible");
		}
	}
}
0