結果

問題 No.4 おもりと天秤
ユーザー ckawatakckawatak
提出日時 2017-07-13 18:30:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 578 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-04-16 18:36:11
合計ジャッジ時間 1,951 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 RE -
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 30 ms
10,880 KB
testcase_05 AC 57 ms
14,976 KB
testcase_06 RE -
testcase_07 AC 60 ms
14,976 KB
testcase_08 AC 31 ms
10,752 KB
testcase_09 AC 49 ms
18,560 KB
testcase_10 AC 63 ms
15,360 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 29 ms
10,752 KB
testcase_18 RE -
testcase_19 AC 56 ms
14,592 KB
testcase_20 AC 55 ms
14,592 KB
testcase_21 AC 55 ms
14,336 KB
testcase_22 AC 59 ms
14,336 KB
権限があれば一括ダウンロードができます

ソースコード

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