結果

問題 No.4 おもりと天秤
ユーザー chocorusk
提出日時 2020-10-03 08:05:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 652 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 75,536 KB
実行使用メモリ 54,468 KB
最終ジャッジ日時 2024-07-18 04:06:30
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=Integer.parseInt(scanner.next());
		int[] w=new int[101];
		for(int i=0; i<n; i++) {
			w[i]=Integer.parseInt(scanner.next());
		}
		boolean[] dp=new boolean[10010];
		dp[0]=true;
		int sum=0;
		for(int i=0; i<n; i++) {
			for(int j=sum; j>=0; j--) {
				if(dp[j]) {
					dp[j+w[i]]=true;
				}
			}
			sum+=w[i];
		}
		if(sum%2==0 && dp[sum/2]) {
			out.println("possible");
		}else {
			out.println("impossible");
		}
		out.flush();
	}
}
0