結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,960 KB
testcase_01 AC 136 ms
57,972 KB
testcase_02 AC 140 ms
57,968 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 155 ms
57,820 KB
testcase_06 AC 135 ms
57,852 KB
testcase_07 AC 152 ms
57,952 KB
testcase_08 AC 143 ms
57,704 KB
testcase_09 AC 149 ms
58,204 KB
testcase_10 AC 154 ms
57,936 KB
testcase_11 AC 132 ms
58,088 KB
testcase_12 WA -
testcase_13 AC 133 ms
57,852 KB
testcase_14 AC 133 ms
57,960 KB
testcase_15 AC 132 ms
57,708 KB
testcase_16 AC 134 ms
57,864 KB
testcase_17 AC 131 ms
57,940 KB
testcase_18 WA -
testcase_19 AC 163 ms
57,952 KB
testcase_20 AC 156 ms
57,832 KB
testcase_21 AC 155 ms
57,980 KB
testcase_22 AC 153 ms
57,980 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[N]){
            System.out.println("possible");
        }else{
            System.out.println("impossible");
        }
    }
}
0