結果

問題 No.4 おもりと天秤
ユーザー neko_the_shadowneko_the_shadow
提出日時 2016-08-27 23:37:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 508 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 10,712 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2023-09-08 17:08:52
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,424 KB
testcase_01 AC 18 ms
8,324 KB
testcase_02 AC 19 ms
8,400 KB
testcase_03 AC 18 ms
8,484 KB
testcase_04 AC 19 ms
8,384 KB
testcase_05 AC 72 ms
8,664 KB
testcase_06 AC 17 ms
8,332 KB
testcase_07 AC 72 ms
8,864 KB
testcase_08 AC 17 ms
8,484 KB
testcase_09 AC 19 ms
8,348 KB
testcase_10 AC 74 ms
8,984 KB
testcase_11 AC 18 ms
8,424 KB
testcase_12 AC 18 ms
8,372 KB
testcase_13 AC 18 ms
8,328 KB
testcase_14 AC 17 ms
8,504 KB
testcase_15 AC 18 ms
8,484 KB
testcase_16 AC 17 ms
8,436 KB
testcase_17 AC 18 ms
8,472 KB
testcase_18 AC 118 ms
8,708 KB
testcase_19 AC 62 ms
8,668 KB
testcase_20 AC 59 ms
8,660 KB
testcase_21 AC 62 ms
8,596 KB
testcase_22 AC 60 ms
8,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, copy

if __name__ == '__main__':
    n = int(input())
    weights = [int(token) for token in input().split(' ')]

    total = sum(weights)
    if total % 2 != 0:
        print("impossible")
        sys.exit(0)

    dest = total // 2
    ht = {}

    for weight in weights:
        temp = copy.deepcopy(ht)
        
        for ky in ht: temp[ky + weight] = True
        temp[weight] = True

        ht = temp
        if dest in ht: break
    
    print("possible" if dest in ht else "impossible")
0