結果

問題 No.4 おもりと天秤
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-04-21 22:04:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 78,716 KB
実行使用メモリ 57,760 KB
最終ジャッジ日時 2023-09-08 16:15:08
合計ジャッジ時間 6,402 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,480 KB
testcase_01 AC 127 ms
56,152 KB
testcase_02 AC 127 ms
56,044 KB
testcase_03 AC 124 ms
56,096 KB
testcase_04 AC 124 ms
57,680 KB
testcase_05 AC 136 ms
56,128 KB
testcase_06 AC 127 ms
56,212 KB
testcase_07 AC 135 ms
55,552 KB
testcase_08 AC 125 ms
55,796 KB
testcase_09 AC 134 ms
56,096 KB
testcase_10 AC 134 ms
55,708 KB
testcase_11 AC 124 ms
57,464 KB
testcase_12 AC 123 ms
56,484 KB
testcase_13 AC 123 ms
55,692 KB
testcase_14 AC 123 ms
55,952 KB
testcase_15 AC 125 ms
56,340 KB
testcase_16 AC 126 ms
56,080 KB
testcase_17 AC 124 ms
53,744 KB
testcase_18 AC 133 ms
56,060 KB
testcase_19 AC 135 ms
56,340 KB
testcase_20 AC 130 ms
55,532 KB
testcase_21 AC 132 ms
56,288 KB
testcase_22 AC 133 ms
57,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.stream.*;

public class Main {
    private void solve() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] ws = Stream.of(sc.nextLine().split(" "))
                              .mapToInt(Integer::parseInt)
                              .toArray();
        int sum = Arrays.stream(ws).sum();
        boolean[] ok = new boolean[sum+1];
        ok[0] = true;
        for(int w : ws) {
            for(int i=sum; i>=0; i--) {
                if(ok[i]) { ok[i+w] = true; }
            }
        }
        System.out.println(ok[sum/2] && sum%2==0 ? "possible" : "impossible");
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}
0