結果

問題 No.4 おもりと天秤
ユーザー chocoruskchocorusk
提出日時 2020-10-03 08:05:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 652 bytes
コンパイル時間 8,532 ms
コンパイル使用メモリ 72,768 KB
実行使用メモリ 56,524 KB
最終ジャッジ日時 2023-09-25 04:48:17
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,524 KB
testcase_01 AC 117 ms
56,340 KB
testcase_02 AC 119 ms
55,692 KB
testcase_03 AC 117 ms
56,096 KB
testcase_04 AC 119 ms
55,980 KB
testcase_05 AC 136 ms
55,588 KB
testcase_06 AC 116 ms
55,724 KB
testcase_07 AC 131 ms
55,896 KB
testcase_08 AC 124 ms
53,748 KB
testcase_09 AC 131 ms
55,808 KB
testcase_10 AC 129 ms
56,140 KB
testcase_11 AC 119 ms
56,372 KB
testcase_12 AC 119 ms
56,100 KB
testcase_13 AC 117 ms
55,596 KB
testcase_14 AC 118 ms
56,092 KB
testcase_15 AC 118 ms
55,912 KB
testcase_16 AC 116 ms
56,144 KB
testcase_17 AC 119 ms
56,244 KB
testcase_18 AC 131 ms
56,444 KB
testcase_19 AC 130 ms
56,104 KB
testcase_20 AC 132 ms
56,144 KB
testcase_21 AC 135 ms
55,992 KB
testcase_22 AC 134 ms
55,304 KB
権限があれば一括ダウンロードができます

ソースコード

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