結果

問題 No.4 おもりと天秤
ユーザー pasoconhoshii
提出日時 2019-02-09 15:34:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 553 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 367,388 KB
最終ジャッジ日時 2024-07-01 19:13:26
合計ジャッジ時間 7,068 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
W = list(map(int, input().split()))

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

from collections import deque
from copy import copy
dq = deque([ (0, [])] ) 
while dq:
    idx, lst = dq.popleft()
    if sum(lst) == total_w//2:
            print("possible")
            exit(0)
    elif idx == N:
        continue
    n_lst = copy(lst)
    dq.append( (idx+1, n_lst) )
    dq.append( (idx+1, n_lst+[W[idx]]) )
print("impossible")


0