結果

問題 No.4 おもりと天秤
ユーザー kou6839kou6839
提出日時 2014-11-08 15:23:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 5,000 ms
コード長 679 bytes
コンパイル時間 3,444 ms
コンパイル使用メモリ 71,636 KB
実行使用メモリ 56,328 KB
最終ジャッジ日時 2023-09-08 16:02:52
合計ジャッジ時間 7,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,756 KB
testcase_01 AC 125 ms
55,524 KB
testcase_02 AC 131 ms
55,684 KB
testcase_03 AC 129 ms
55,636 KB
testcase_04 AC 129 ms
55,952 KB
testcase_05 AC 137 ms
56,088 KB
testcase_06 AC 123 ms
55,824 KB
testcase_07 AC 142 ms
55,952 KB
testcase_08 AC 133 ms
55,760 KB
testcase_09 AC 140 ms
55,836 KB
testcase_10 AC 138 ms
55,824 KB
testcase_11 AC 125 ms
56,008 KB
testcase_12 AC 123 ms
55,620 KB
testcase_13 AC 121 ms
55,616 KB
testcase_14 AC 125 ms
55,900 KB
testcase_15 AC 122 ms
55,956 KB
testcase_16 AC 128 ms
55,828 KB
testcase_17 AC 137 ms
55,636 KB
testcase_18 AC 141 ms
55,944 KB
testcase_19 AC 140 ms
56,328 KB
testcase_20 AC 140 ms
56,212 KB
testcase_21 AC 140 ms
54,292 KB
testcase_22 AC 141 ms
55,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int sum=0;
		int[] omori = new int[N];
		for(int i=0;i<N;i++){
			int temp=sc.nextInt();
			sum+=temp;
			omori[i]=temp;
		}
		if(!(sum%2==0)){
			System.out.println("impossible");
			return;
		}
		boolean[] check = new boolean[10001];
		check[0]=true;
		for(int i=0;i<N;i++){
			for(int j=10000;j>=0;j--){
				if(check[j]&&!check[j+omori[i]]){
					check[j+omori[i]]=true;
				}
			}
		}
		if(check[sum/2]){
			System.out.println("possible");
		}else{
			System.out.println("impossible");
		}
	}
}
0