結果

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

ソースコード

diff #

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

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

if total%2 != 0:
    print('impossible')
    exit()
    
d = []
for i in range(n+1):
    r = [None] * total
    d.append(r)
    
target = total//2

def yes(i, sum):
    if d[i][sum] != None:
        return d[i][sum]

    result = None
    if n == i:
        result = (sum == target)
    else:
        result = (yes(i+1, sum) or yes(i+1, sum+values[i]))
    d[i][sum] = result
    
    return result

print('possible' if yes(0,0) else 'impossible')
0