結果

問題 No.4 おもりと天秤
ユーザー 37zigen37zigen
提出日時 2016-03-07 23:37:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 812 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 77,456 KB
実行使用メモリ 58,224 KB
最終ジャッジ日時 2023-10-24 19:13:13
合計ジャッジ時間 5,993 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 120 ms
40,948 KB
testcase_02 AC 127 ms
40,448 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 114 ms
40,824 KB
testcase_07 WA -
testcase_08 AC 131 ms
41,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 122 ms
40,728 KB
testcase_12 AC 118 ms
40,928 KB
testcase_13 AC 113 ms
41,036 KB
testcase_14 AC 120 ms
40,996 KB
testcase_15 AC 118 ms
40,816 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 132 ms
41,140 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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