結果

問題 No.4 おもりと天秤
ユーザー nCk_cvnCk_cv
提出日時 2016-02-06 17:13:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 656 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 74,208 KB
実行使用メモリ 56,476 KB
最終ジャッジ日時 2023-09-08 16:32:12
合計ジャッジ時間 5,920 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,880 KB
testcase_01 AC 122 ms
56,120 KB
testcase_02 AC 122 ms
55,808 KB
testcase_03 AC 121 ms
55,804 KB
testcase_04 AC 122 ms
55,964 KB
testcase_05 AC 140 ms
55,844 KB
testcase_06 AC 122 ms
56,460 KB
testcase_07 AC 137 ms
55,872 KB
testcase_08 AC 129 ms
55,776 KB
testcase_09 AC 140 ms
56,224 KB
testcase_10 AC 137 ms
55,964 KB
testcase_11 AC 120 ms
55,728 KB
testcase_12 AC 121 ms
56,220 KB
testcase_13 AC 120 ms
55,868 KB
testcase_14 AC 119 ms
56,268 KB
testcase_15 AC 121 ms
56,084 KB
testcase_16 AC 123 ms
56,060 KB
testcase_17 AC 120 ms
56,340 KB
testcase_18 AC 137 ms
56,128 KB
testcase_19 AC 139 ms
55,740 KB
testcase_20 AC 137 ms
56,388 KB
testcase_21 AC 138 ms
56,476 KB
testcase_22 AC 137 ms
55,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.io.*;
 
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];
		}
		boolean[][] dp = new boolean[n+1][sum+1];
		dp[0][0] = true;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= sum; j++) {
				if(!dp[i][j]) continue;
				dp[i+1][j] |= dp[i][j];
				dp[i+1][j + w[i]] = true; 
			}
		}
		if(sum % 2 == 0 && dp[n][sum / 2]) {
			System.out.println("possible");
		}
		else {
			System.out.println("impossible");
		}
	}
}
0