結果

問題 No.4 おもりと天秤
ユーザー DAZYDAZY
提出日時 2017-05-24 15:25:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 727 bytes
コンパイル時間 3,281 ms
コンパイル使用メモリ 71,428 KB
実行使用メモリ 56,164 KB
最終ジャッジ日時 2023-09-08 17:29:35
合計ジャッジ時間 7,597 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,536 KB
testcase_01 AC 129 ms
55,848 KB
testcase_02 AC 141 ms
55,768 KB
testcase_03 AC 137 ms
55,600 KB
testcase_04 AC 137 ms
55,704 KB
testcase_05 AC 146 ms
55,460 KB
testcase_06 AC 126 ms
55,784 KB
testcase_07 AC 147 ms
55,952 KB
testcase_08 AC 147 ms
55,608 KB
testcase_09 AC 151 ms
56,044 KB
testcase_10 AC 146 ms
55,988 KB
testcase_11 AC 129 ms
55,880 KB
testcase_12 AC 127 ms
55,612 KB
testcase_13 AC 130 ms
55,712 KB
testcase_14 AC 127 ms
55,752 KB
testcase_15 AC 129 ms
56,008 KB
testcase_16 AC 132 ms
55,668 KB
testcase_17 AC 128 ms
55,672 KB
testcase_18 AC 146 ms
55,848 KB
testcase_19 AC 149 ms
55,816 KB
testcase_20 AC 147 ms
55,760 KB
testcase_21 AC 146 ms
56,164 KB
testcase_22 AC 147 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No4 {
    public static void main (String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int t, sum = 0;
        //インデックスのおもさを作り出せるかどうか
        int[] w = new int[10001];
        w[0] = 1;
        for (int i = 1; i < 10001; i++) w[i] = 0;
        for (int i = 0; i < N; i++) {
            t = scan.nextInt();
            sum += t;
            for (int j = 10000 - t; j >= 0; j--) w[j+t] += w[j];
        }
        //二等分できないとき、または半分のおもさにできない場合 impossible
        System.out.println((sum & 1)==1 || w[sum/2]==0 ? "impossible" : "possible");
    }
}
0