結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,828 KB
testcase_01 AC 134 ms
57,832 KB
testcase_02 AC 136 ms
57,828 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 131 ms
57,552 KB
testcase_07 WA -
testcase_08 AC 139 ms
57,652 KB
testcase_09 AC 150 ms
57,788 KB
testcase_10 WA -
testcase_11 AC 131 ms
57,832 KB
testcase_12 WA -
testcase_13 AC 131 ms
57,840 KB
testcase_14 WA -
testcase_15 AC 133 ms
57,712 KB
testcase_16 WA -
testcase_17 AC 131 ms
57,828 KB
testcase_18 AC 155 ms
57,708 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
        int h = sum / 2;
        boolean[][] dp = new boolean[h + 1][N];
        for (int i = 0; i < dp.length; i++) {
            dp[i][0] = true;
        }
        for (int i = 0; i < dp[0].length; i++) {
            dp[0][i] = true;
        }

        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[0].length; j++) {
                if (dp[i][j] && i + w[j] <= h) {
                    dp[i + w[j]][j] = true;
                }
            }
        }
        if (dp[h][N - 1])

        {
            System.out.println("possible");
        } else {
            System.out.println("impossible");
        }
    }
}
0