結果

問題 No.4 おもりと天秤
ユーザー villachvillach
提出日時 2017-10-05 16:24:24
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 959 bytes
コンパイル時間 2,939 ms
コンパイル使用メモリ 77,948 KB
実行使用メモリ 54,220 KB
最終ジャッジ日時 2024-04-28 07:32:49
合計ジャッジ時間 6,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
53,780 KB
testcase_01 AC 117 ms
53,636 KB
testcase_02 AC 106 ms
53,256 KB
testcase_03 AC 118 ms
53,808 KB
testcase_04 AC 121 ms
53,704 KB
testcase_05 AC 131 ms
54,168 KB
testcase_06 AC 109 ms
53,600 KB
testcase_07 AC 135 ms
54,192 KB
testcase_08 AC 129 ms
53,952 KB
testcase_09 RE -
testcase_10 AC 129 ms
53,896 KB
testcase_11 AC 105 ms
53,088 KB
testcase_12 AC 106 ms
52,988 KB
testcase_13 AC 115 ms
53,864 KB
testcase_14 AC 116 ms
53,904 KB
testcase_15 AC 114 ms
53,852 KB
testcase_16 AC 122 ms
53,864 KB
testcase_17 AC 105 ms
53,000 KB
testcase_18 AC 133 ms
54,160 KB
testcase_19 AC 130 ms
53,808 KB
testcase_20 AC 140 ms
53,672 KB
testcase_21 AC 133 ms
53,372 KB
testcase_22 AC 138 ms
54,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.ArrayList;
import java.util.Scanner;

public class N4 {
	private int n, sum, half;
	private int[] bobs;
	private boolean[][] dp;
	
	public static void main(String[] args){
		N4 n4 = new N4();
	}

	N4(){
		Scanner sc = new Scanner(System.in);
		this.n = sc.nextInt();
		this.bobs = new int[n];
		this.dp = new boolean[n + 1][10000];
		
		for(int i = 0;i < n;++i){
			bobs[i] = sc.nextInt();
			sum += bobs[i];
		}
		
		if(sum % 2 == 1){
			System.out.println("impossible");
			return;
		}
		
		this.half = sum / 2;
		
		if(this.solve()){
			System.out.println("possible");
		}else{
			System.out.println("impossible");
		}
	}
	
	//めう
	private boolean solve() {
		dp[0][0] = true;
		for(int k = 0;k < n;++k){
			int b = bobs[k];
			for(int weight = 0;weight < 10000;++weight){
				if(dp[k][weight]){
					dp[k + 1][weight + b] = true;
					dp[k + 1][weight] = true;
				}
			}
		}
		
		return dp[this.n - 1][half];
	}
}
0