結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,552 KB
testcase_01 AC 43 ms
49,224 KB
testcase_02 AC 48 ms
49,520 KB
testcase_03 AC 44 ms
49,404 KB
testcase_04 AC 43 ms
49,412 KB
testcase_05 AC 44 ms
49,316 KB
testcase_06 AC 43 ms
49,624 KB
testcase_07 AC 45 ms
49,428 KB
testcase_08 AC 43 ms
49,252 KB
testcase_09 AC 44 ms
49,428 KB
testcase_10 AC 43 ms
47,244 KB
testcase_11 AC 42 ms
49,564 KB
testcase_12 AC 43 ms
49,376 KB
testcase_13 AC 44 ms
49,400 KB
testcase_14 AC 43 ms
49,484 KB
testcase_15 AC 42 ms
49,500 KB
testcase_16 AC 43 ms
49,744 KB
testcase_17 AC 43 ms
49,400 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 (i >= nums.length || sum > target) 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