結果

問題 No.4 おもりと天秤
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-05-07 23:13:18
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,352 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 73,960 KB
実行使用メモリ 51,508 KB
最終ジャッジ日時 2023-10-12 16:15:21
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,360 KB
testcase_01 AC 46 ms
49,260 KB
testcase_02 AC 46 ms
49,404 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 46 ms
49,504 KB
testcase_07 WA -
testcase_08 AC 46 ms
49,240 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 46 ms
49,396 KB
testcase_12 AC 46 ms
49,248 KB
testcase_13 AC 46 ms
49,500 KB
testcase_14 AC 46 ms
49,264 KB
testcase_15 AC 45 ms
49,708 KB
testcase_16 WA -
testcase_17 AC 45 ms
49,252 KB
testcase_18 AC 46 ms
49,328 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        String[] inputs = reader.readLine().split(" ");
        int[] weights = new int[N];
        int sumOfWeights = 0;

        for (int i = 0; i < N; i++) {
            int weight = Integer.parseInt(inputs[i]);
            weights[i] = weight;
            sumOfWeights += weight;
        }

        if (sumOfWeights % 2 != 0) {
            System.out.println("impossible");
        } else {

            int requiredWeight = sumOfWeights / 2;
            boolean[][] dp = new boolean[101][10001];
            dp[0][0] = true;

            for (int i = 0; i < N; i++) {
                for (int j = 0; j <= 10; j++) {
                    if (dp[i][j]) {
                        dp[i + 1][j + weights[i]] = true;
                        dp[i + 1][j] = true;
                    }
                }
            }
            if (dp[N][requiredWeight]) {
                System.out.println("possible");
            } else {
                System.out.println("impossible");
            }
        }
    }
}
0