結果

問題 No.4 おもりと天秤
ユーザー pasoconhoshiipasoconhoshii
提出日時 2019-02-09 15:51:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 435 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 10,708 KB
実行使用メモリ 8,540 KB
最終ジャッジ日時 2023-09-14 11:46:12
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,216 KB
testcase_01 AC 17 ms
8,104 KB
testcase_02 AC 16 ms
7,832 KB
testcase_03 AC 15 ms
8,180 KB
testcase_04 AC 16 ms
8,084 KB
testcase_05 AC 40 ms
8,512 KB
testcase_06 AC 16 ms
7,784 KB
testcase_07 AC 39 ms
8,496 KB
testcase_08 AC 16 ms
8,180 KB
testcase_09 AC 16 ms
8,132 KB
testcase_10 AC 41 ms
8,540 KB
testcase_11 AC 16 ms
7,816 KB
testcase_12 AC 16 ms
7,812 KB
testcase_13 AC 15 ms
7,908 KB
testcase_14 AC 16 ms
7,932 KB
testcase_15 AC 16 ms
7,808 KB
testcase_16 AC 16 ms
8,040 KB
testcase_17 AC 16 ms
8,100 KB
testcase_18 AC 48 ms
8,264 KB
testcase_19 AC 35 ms
8,496 KB
testcase_20 AC 34 ms
8,540 KB
testcase_21 AC 36 ms
8,380 KB
testcase_22 AC 35 ms
8,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = list(map(int, input().split()))

total_w = sum(W)
if total_w % 2 == 1:
    print("impossible")
    exit(0)

setw = set([0])

for w in W:
    new_setw = set(setw) # cannot change set size inside loop
    for v in setw:
        nv = v + w
        if nv == total_w//2:
            print("possible")
            exit(0)
        if nv < total_w//2:
            new_setw.add(nv)
    setw = new_setw

print("impossible")
0