結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-03-07 23:40:30 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 154 ms / 5,000 ms | 
| コード長 | 813 bytes | 
| コンパイル時間 | 2,460 ms | 
| コンパイル使用メモリ | 77,464 KB | 
| 実行使用メモリ | 41,564 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:27:00 | 
| 合計ジャッジ時間 | 6,176 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
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();
	} 
}
            
            
            
        