結果

問題 No.4 おもりと天秤
ユーザー ckawatakckawatak
提出日時 2017-07-13 18:37:17
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 582 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 16,520 KB
最終ジャッジ日時 2023-09-08 17:32:21
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,624 KB
testcase_01 AC 20 ms
8,596 KB
testcase_02 AC 21 ms
8,796 KB
testcase_03 AC 21 ms
8,656 KB
testcase_04 AC 20 ms
8,668 KB
testcase_05 AC 49 ms
12,744 KB
testcase_06 AC 20 ms
8,752 KB
testcase_07 AC 51 ms
12,724 KB
testcase_08 AC 21 ms
8,756 KB
testcase_09 AC 41 ms
16,520 KB
testcase_10 AC 57 ms
13,352 KB
testcase_11 AC 20 ms
8,720 KB
testcase_12 AC 21 ms
8,676 KB
testcase_13 AC 20 ms
8,808 KB
testcase_14 AC 20 ms
8,760 KB
testcase_15 AC 21 ms
8,628 KB
testcase_16 AC 20 ms
8,764 KB
testcase_17 AC 20 ms
8,624 KB
testcase_18 AC 69 ms
12,468 KB
testcase_19 AC 47 ms
12,296 KB
testcase_20 AC 47 ms
12,204 KB
testcase_21 AC 46 ms
12,036 KB
testcase_22 AC 48 ms
12,200 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+1)
    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