結果

問題 No.4 おもりと天秤
コンテスト
ユーザー kou6839
提出日時 2014-11-08 15:23:21
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 679 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,796 ms
コンパイル使用メモリ 84,268 KB
実行使用メモリ 48,044 KB
最終ジャッジ日時 2026-03-13 01:26:01
合計ジャッジ時間 5,919 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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