結果

問題 No.4 おもりと天秤
ユーザー neko_the_shadow
提出日時 2016-08-27 23:34:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 508 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-11-08 20:02:48
合計ジャッジ時間 2,931 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 RE * 2
権限があれば一括ダウンロードができます

ソースコード

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(1)

    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