結果

問題 No.4 おもりと天秤
ユーザー ckawatak
提出日時 2017-07-13 17:19:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 595 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-10-07 18:21:47
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
values = list(map(int, input().split(' ')))

import functools
from collections import deque

total = functools.reduce(lambda x,y: x+y, values)

def yes(target):
    queue = deque()
    queue.appendleft((0,0))

    while 0 < len(queue):
        i, sum = queue.popleft()

        if sum == target:
            return True

        if i == n:
            return False

        queue.appendleft((i+1,sum))
        queue.appendleft((i+1,sum+values[i]))
        
    return False

if total%2 != 0:
    print('impossible')
else:
    print('possible' if yes(total/2) else 'impossible')
0