結果

問題 No.4 おもりと天秤
ユーザー mosmos_21mosmos_21
提出日時 2017-06-17 11:30:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 931 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 75,184 KB
実行使用メモリ 58,212 KB
最終ジャッジ日時 2024-04-08 17:25:30
合計ジャッジ時間 6,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,832 KB
testcase_01 AC 131 ms
57,828 KB
testcase_02 AC 133 ms
57,820 KB
testcase_03 AC 130 ms
57,844 KB
testcase_04 AC 133 ms
57,840 KB
testcase_05 AC 152 ms
57,932 KB
testcase_06 AC 131 ms
57,836 KB
testcase_07 AC 151 ms
57,820 KB
testcase_08 AC 138 ms
57,596 KB
testcase_09 AC 147 ms
57,960 KB
testcase_10 AC 152 ms
57,840 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 130 ms
57,836 KB
testcase_14 WA -
testcase_15 AC 127 ms
57,700 KB
testcase_16 AC 130 ms
57,836 KB
testcase_17 AC 136 ms
57,708 KB
testcase_18 AC 151 ms
58,084 KB
testcase_19 AC 158 ms
57,732 KB
testcase_20 AC 157 ms
58,084 KB
testcase_21 AC 149 ms
57,712 KB
testcase_22 AC 151 ms
58,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[] w = new int[N];
        int sum = 0;

        for(int i = 0; i < N; i++){
            w[i] = in.nextInt();
            sum += w[i];
        }

        if(sum % 2 == 1){
            System.out.println("impossible");
            return;
        }

        boolean[] dp = new boolean[sum / 2 + 1];
        Arrays.fill(dp, false);
        dp[0] = true;
        for(int i = 0; i < dp.length; i++){
            for(int j = 0; j < w.length; j++){
                if(dp[i] && i + w[j] < dp.length){
                    dp[i + w[j]] = true;
                }
            }
        }
        if(dp[sum / 2]){
            System.out.println("possible");
        }else{
            System.out.println("impossible");
        }
    }
}
0