結果

問題 No.4 おもりと天秤
ユーザー kou6839
提出日時 2014-11-08 15:23:21
言語 Java
(openjdk 23)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 679 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 74,744 KB
実行使用メモリ 54,244 KB
最終ジャッジ日時 2024-06-26 09:02:56
合計ジャッジ時間 7,070 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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