結果

問題 No.4 おもりと天秤
ユーザー sue_charosue_charo
提出日時 2017-04-12 19:27:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 419 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 10,704 KB
実行使用メモリ 7,984 KB
最終ジャッジ日時 2023-09-08 17:24:02
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,940 KB
testcase_01 AC 16 ms
7,804 KB
testcase_02 AC 17 ms
7,796 KB
testcase_03 AC 15 ms
7,912 KB
testcase_04 AC 16 ms
7,820 KB
testcase_05 AC 65 ms
7,816 KB
testcase_06 AC 15 ms
7,976 KB
testcase_07 AC 69 ms
7,844 KB
testcase_08 AC 15 ms
7,772 KB
testcase_09 AC 64 ms
7,796 KB
testcase_10 AC 74 ms
7,808 KB
testcase_11 AC 15 ms
7,984 KB
testcase_12 AC 15 ms
7,796 KB
testcase_13 AC 15 ms
7,828 KB
testcase_14 AC 16 ms
7,840 KB
testcase_15 AC 16 ms
7,844 KB
testcase_16 AC 15 ms
7,800 KB
testcase_17 AC 15 ms
7,844 KB
testcase_18 AC 52 ms
7,952 KB
testcase_19 AC 63 ms
7,980 KB
testcase_20 AC 62 ms
7,896 KB
testcase_21 AC 59 ms
7,936 KB
testcase_22 AC 62 ms
7,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
N = int(input())
W = list(map(int, input().split()))


if sum(W) % 2:
    print("impossible")
else:
    num_sum = sum(W) // 2

    dp = [0] * (sum(W) + 1)
    dp[0] = 1
    total = 0
    for w in W:
        total += w
        for i in range(total, -1, -1):
            if dp[i] == 1:
                dp[i + w] = 1
    
    if dp[num_sum]:
        print("possible")
    else:
        print("impossible")
0