結果

問題 No.4 おもりと天秤
ユーザー HiroK_abcHiroK_abc
提出日時 2017-06-17 10:23:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 484 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 8,940 KB
最終ジャッジ日時 2023-09-08 17:30:36
合計ジャッジ時間 1,912 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,796 KB
testcase_01 AC 16 ms
7,832 KB
testcase_02 AC 16 ms
7,920 KB
testcase_03 AC 16 ms
7,864 KB
testcase_04 AC 16 ms
8,216 KB
testcase_05 AC 71 ms
8,940 KB
testcase_06 AC 15 ms
8,016 KB
testcase_07 AC 74 ms
8,796 KB
testcase_08 AC 16 ms
7,792 KB
testcase_09 AC 17 ms
7,744 KB
testcase_10 AC 76 ms
8,852 KB
testcase_11 AC 16 ms
7,744 KB
testcase_12 AC 16 ms
7,856 KB
testcase_13 AC 16 ms
7,856 KB
testcase_14 AC 16 ms
7,840 KB
testcase_15 AC 15 ms
7,908 KB
testcase_16 AC 16 ms
7,864 KB
testcase_17 AC 15 ms
7,848 KB
testcase_18 AC 44 ms
8,472 KB
testcase_19 AC 67 ms
8,640 KB
testcase_20 AC 67 ms
8,596 KB
testcase_21 AC 65 ms
8,584 KB
testcase_22 AC 66 ms
8,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
ws = list(map(int, input().split()))
W = sum(ws) // 2

if sum(ws) % 2 != 0:
    print('impossible')
elif W < max(ws):
    print('impossible')
else:
    psb_ws = set([0])
    ws.sort()
    while len(ws) > 0:
        w = ws.pop()
        tmp_set = set()
        for psb_w in psb_ws:
            if psb_w + w <= W:
                tmp_set.add(psb_w + w)
        psb_ws.update(tmp_set)
    if W in psb_ws:
        print('possible')
    else:
        print('impossible')

0