結果

問題 No.4 おもりと天秤
ユーザー qewqewqewqewqewqew
提出日時 2018-12-15 03:04:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 280 ms / 5,000 ms
コード長 467 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2023-10-25 10:42:52
合計ジャッジ時間 2,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,164 KB
testcase_01 AC 28 ms
10,164 KB
testcase_02 AC 29 ms
10,204 KB
testcase_03 AC 28 ms
10,164 KB
testcase_04 AC 29 ms
10,216 KB
testcase_05 AC 117 ms
12,276 KB
testcase_06 AC 26 ms
10,164 KB
testcase_07 AC 115 ms
12,296 KB
testcase_08 AC 27 ms
10,164 KB
testcase_09 AC 280 ms
14,068 KB
testcase_10 AC 134 ms
12,544 KB
testcase_11 AC 27 ms
10,164 KB
testcase_12 AC 27 ms
10,164 KB
testcase_13 AC 28 ms
10,164 KB
testcase_14 AC 28 ms
10,164 KB
testcase_15 AC 27 ms
10,164 KB
testcase_16 AC 26 ms
10,164 KB
testcase_17 AC 25 ms
10,164 KB
testcase_18 AC 136 ms
12,176 KB
testcase_19 AC 106 ms
12,064 KB
testcase_20 AC 107 ms
12,052 KB
testcase_21 AC 101 ms
11,936 KB
testcase_22 AC 104 ms
11,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
ws = list(map(int, input().split()))

sum_w = sum(ws)
if sum_w % 2:
    print("impossible")
    exit()

dp = [[False]*(sum_w//2+1) for i in range(n+1)]
dp[0][0] = True
for i in range(1, n+1):
    for w in range(sum_w//2+1):
        if w - ws[i-1] >= 0:
            dp[i][w] = dp[i-1][w] or dp[i-1][w-ws[i-1]]
        else:
            dp[i][w] = dp[i-1][w]

if any([dp[i][-1] for i in range(n+1)]):
    print("possible")
else:
    print("impossible")
0