結果

問題 No.4 おもりと天秤
ユーザー 37zigen37zigen
提出日時 2016-03-07 23:40:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 145 ms / 5,000 ms
コード長 813 bytes
コンパイル時間 1,970 ms
コンパイル使用メモリ 74,176 KB
実行使用メモリ 56,224 KB
最終ジャッジ日時 2023-09-08 16:36:32
合計ジャッジ時間 6,124 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,816 KB
testcase_01 AC 124 ms
55,480 KB
testcase_02 AC 132 ms
55,932 KB
testcase_03 AC 128 ms
55,808 KB
testcase_04 AC 133 ms
55,572 KB
testcase_05 AC 145 ms
55,924 KB
testcase_06 AC 123 ms
55,732 KB
testcase_07 AC 142 ms
55,912 KB
testcase_08 AC 130 ms
55,464 KB
testcase_09 AC 144 ms
56,200 KB
testcase_10 AC 144 ms
53,600 KB
testcase_11 AC 126 ms
55,448 KB
testcase_12 AC 126 ms
55,688 KB
testcase_13 AC 125 ms
55,796 KB
testcase_14 AC 124 ms
55,772 KB
testcase_15 AC 122 ms
55,676 KB
testcase_16 AC 128 ms
55,464 KB
testcase_17 AC 127 ms
55,744 KB
testcase_18 AC 142 ms
55,948 KB
testcase_19 AC 142 ms
55,932 KB
testcase_20 AC 144 ms
55,916 KB
testcase_21 AC 143 ms
56,088 KB
testcase_22 AC 142 ms
56,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static int mod=1000003;
	public static void main(String[] args) throws Exception {
		PrintWriter pw=new PrintWriter(System.out);
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int sum=0;
		int[] w=new int[n];
		for(int i=0;i<n;i++){
			int tmp=sc.nextInt();
			sum+=tmp;
			w[i]=tmp;
		}
		if(sum%2!=0){
			pw.println("impossible");
			pw.close();
			return;
		}
		
		boolean[] check=new boolean[10001];
		Arrays.fill(check,false);
		check[0]=true;

		for(int i=0;i<n;i++){
			for(int j=10000;j-w[i]>=0;j--){
				if(!check[j]&&check[j-w[i]]){
					check[j]=true;
				}
			}
		}
		if(check[sum/2]){
			pw.print("possible");
		}else{
			pw.print("impossible");
		}
		pw.close();
		sc.close();
	} 
}
0