結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,512 KB
testcase_01 AC 43 ms
49,256 KB
testcase_02 AC 45 ms
49,540 KB
testcase_03 AC 43 ms
49,516 KB
testcase_04 AC 43 ms
49,300 KB
testcase_05 AC 52 ms
49,516 KB
testcase_06 AC 44 ms
47,780 KB
testcase_07 AC 51 ms
49,792 KB
testcase_08 AC 43 ms
49,420 KB
testcase_09 AC 53 ms
50,044 KB
testcase_10 AC 56 ms
50,948 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 45 ms
49,660 KB
testcase_14 WA -
testcase_15 AC 44 ms
49,488 KB
testcase_16 AC 44 ms
49,308 KB
testcase_17 AC 44 ms
49,352 KB
testcase_18 AC 49 ms
49,776 KB
testcase_19 AC 50 ms
49,488 KB
testcase_20 AC 50 ms
50,052 KB
testcase_21 AC 51 ms
49,432 KB
testcase_22 AC 49 ms
49,300 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++) {
			for (int j = 0; j <= target; j++) {
				if (!dp[j]) continue;
				if (nums[i] + j <= target)
					dp[nums[i] + j] = 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