結果

問題 No.4 おもりと天秤
ユーザー Flere0114Flere0114
提出日時 2016-02-17 16:11:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 905 bytes
コンパイル時間 3,693 ms
コンパイル使用メモリ 74,864 KB
実行使用メモリ 57,836 KB
最終ジャッジ日時 2023-10-22 06:14:18
合計ジャッジ時間 8,359 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,072 KB
testcase_01 AC 131 ms
57,384 KB
testcase_02 WA -
testcase_03 AC 126 ms
57,328 KB
testcase_04 AC 128 ms
57,396 KB
testcase_05 AC 141 ms
57,452 KB
testcase_06 WA -
testcase_07 AC 146 ms
57,288 KB
testcase_08 AC 136 ms
57,508 KB
testcase_09 WA -
testcase_10 AC 143 ms
57,548 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 130 ms
57,264 KB
testcase_14 AC 133 ms
57,360 KB
testcase_15 AC 131 ms
57,056 KB
testcase_16 AC 132 ms
57,332 KB
testcase_17 AC 131 ms
57,556 KB
testcase_18 WA -
testcase_19 AC 149 ms
57,384 KB
testcase_20 AC 145 ms
57,576 KB
testcase_21 AC 149 ms
57,652 KB
testcase_22 AC 149 ms
57,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] w = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            w[i] = Integer.parseInt(sc.next());
            sum += w[i];
        }

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

        int half = sum / 2;
        boolean[] dp = new boolean[half];
        dp[0] = true;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < half; j++) {
                if(dp[j] && j+w[i] < half){
                    dp[j+w[i]] = true;
                }
            }
        }
        if(dp[half-1]){
            System.out.println("possible");
        }else{
            System.out.println("impossible");
        }
    }
}
0