結果

問題 No.4 おもりと天秤
ユーザー spaciaspacia
提出日時 2015-12-19 09:48:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 827 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 72,332 KB
実行使用メモリ 55,436 KB
最終ジャッジ日時 2023-10-14 14:16:12
合計ジャッジ時間 9,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
49,560 KB
testcase_01 AC 41 ms
49,360 KB
testcase_02 AC 45 ms
49,624 KB
testcase_03 AC 40 ms
49,360 KB
testcase_04 AC 39 ms
49,468 KB
testcase_05 AC 40 ms
49,328 KB
testcase_06 AC 37 ms
49,276 KB
testcase_07 AC 40 ms
49,228 KB
testcase_08 AC 36 ms
47,164 KB
testcase_09 AC 39 ms
49,532 KB
testcase_10 AC 37 ms
49,284 KB
testcase_11 AC 39 ms
49,552 KB
testcase_12 AC 37 ms
49,556 KB
testcase_13 AC 36 ms
49,520 KB
testcase_14 AC 36 ms
49,736 KB
testcase_15 AC 35 ms
49,268 KB
testcase_16 AC 35 ms
49,228 KB
testcase_17 AC 36 ms
49,572 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main4 {
	
	static int target = 0;
	static int[] nums;
	
	public static boolean dp (int i, int sum) {
		if (sum > target || i >= nums.length) return false;
		if (sum == target) return true;
		
		if (dp(i + 1, sum + nums[i]) || dp(i + 1, sum))
			return true;
		return false;
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		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(dp(0, 0) ? "possible" : "impossible");
		}
	}
}
0