結果

問題 No.4 おもりと天秤
ユーザー fal_rndfal_rnd
提出日時 2017-01-20 22:08:50
言語 Java19
(openjdk 21)
結果
AC  
実行時間 137 ms / 5,000 ms
コード長 541 bytes
コンパイル時間 4,963 ms
コンパイル使用メモリ 72,608 KB
実行使用メモリ 56,144 KB
最終ジャッジ日時 2023-09-08 17:18:07
合計ジャッジ時間 9,099 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,016 KB
testcase_01 AC 117 ms
55,888 KB
testcase_02 AC 126 ms
55,652 KB
testcase_03 AC 120 ms
55,964 KB
testcase_04 AC 121 ms
55,912 KB
testcase_05 AC 132 ms
55,960 KB
testcase_06 AC 119 ms
55,976 KB
testcase_07 AC 134 ms
55,908 KB
testcase_08 AC 127 ms
56,144 KB
testcase_09 AC 136 ms
55,936 KB
testcase_10 AC 136 ms
56,020 KB
testcase_11 AC 124 ms
55,732 KB
testcase_12 AC 117 ms
55,944 KB
testcase_13 AC 122 ms
55,940 KB
testcase_14 AC 124 ms
55,676 KB
testcase_15 AC 125 ms
56,024 KB
testcase_16 AC 126 ms
55,524 KB
testcase_17 AC 125 ms
56,000 KB
testcase_18 AC 136 ms
55,364 KB
testcase_19 AC 136 ms
55,600 KB
testcase_20 AC 137 ms
55,960 KB
testcase_21 AC 136 ms
55,516 KB
testcase_22 AC 135 ms
55,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package src;

import java.util.*;
public class A{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int sum=0;
		int[] in = new int[s.nextInt()];
		for(int i=0;i<in.length;i++)
			sum+=(in[i]=s.nextInt());
		if(sum%2!=0) {
			System.out.println("impossible");
			return;
		}
		Arrays.sort(in);
		boolean[] dp = new boolean[10001];
		dp[0]=true;
		for(int i:in) {
			for(int d=dp.length-1;d>=0;d--) {
				if(dp[d])
					dp[d+i]=true;
			}
		}
		System.out.println(dp[sum/2]?"possible":"impossible");
	}
}
0