結果

問題 No.4 おもりと天秤
ユーザー spaciaspacia
提出日時 2015-12-19 11:08:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 72,220 KB
実行使用メモリ 50,044 KB
最終ジャッジ日時 2023-10-14 14:16:52
合計ジャッジ時間 4,122 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,300 KB
testcase_01 AC 43 ms
49,420 KB
testcase_02 AC 43 ms
49,308 KB
testcase_03 WA -
testcase_04 AC 44 ms
49,600 KB
testcase_05 WA -
testcase_06 AC 43 ms
49,548 KB
testcase_07 WA -
testcase_08 AC 44 ms
47,920 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 42 ms
49,596 KB
testcase_12 AC 43 ms
49,524 KB
testcase_13 AC 43 ms
49,372 KB
testcase_14 AC 43 ms
49,888 KB
testcase_15 AC 43 ms
50,044 KB
testcase_16 AC 43 ms
49,532 KB
testcase_17 WA -
testcase_18 AC 48 ms
49,476 KB
testcase_19 AC 51 ms
49,328 KB
testcase_20 AC 51 ms
49,408 KB
testcase_21 WA -
testcase_22 AC 50 ms
49,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main4 {
	
	public static boolean check (int[] nums, int target) {
		boolean[] dp = new boolean[target + 1];
		
		Arrays.sort(nums);
		dp[0] = true;
		for (int i = 0; i < nums.length; i++) {
			boolean[] addFlg = new boolean[target + 1];
			for (int j = 0; j <= target; j++) {
				if (!dp[j] || addFlg[j]) continue;
				int res = nums[i] + j;
				if (res <= target) {
					dp[res] = true;
					addFlg[res] = true;
				} else
					break;
			}
		}
		return dp[target];
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		int target = 0;
		int[] nums = new int[n];
		String[] str = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(str[i]);
			target += nums[i];
		}
		if (target % 2 == 1)
			System.out.println("impossible");
		else {
			target /= 2;
			System.out.println(check(nums, target) ? "possible" : "impossible");
		}
	}
}
0