結果

問題 No.4 おもりと天秤
ユーザー shokayamorishokayamori
提出日時 2020-12-05 20:50:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 442 ms / 5,000 ms
コード長 468 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 10,912 KB
実行使用メモリ 16,132 KB
最終ジャッジ日時 2023-10-14 08:11:31
合計ジャッジ時間 4,205 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,908 KB
testcase_01 AC 15 ms
8,100 KB
testcase_02 AC 21 ms
8,196 KB
testcase_03 AC 17 ms
7,760 KB
testcase_04 AC 22 ms
8,372 KB
testcase_05 AC 294 ms
12,436 KB
testcase_06 AC 16 ms
7,956 KB
testcase_07 AC 307 ms
12,336 KB
testcase_08 AC 16 ms
8,252 KB
testcase_09 AC 442 ms
16,132 KB
testcase_10 AC 319 ms
12,888 KB
testcase_11 AC 17 ms
7,840 KB
testcase_12 AC 16 ms
7,800 KB
testcase_13 AC 17 ms
7,864 KB
testcase_14 AC 16 ms
7,940 KB
testcase_15 AC 16 ms
7,852 KB
testcase_16 AC 18 ms
7,780 KB
testcase_17 AC 16 ms
7,852 KB
testcase_18 AC 266 ms
12,156 KB
testcase_19 AC 250 ms
11,912 KB
testcase_20 AC 280 ms
11,888 KB
testcase_21 AC 257 ms
11,652 KB
testcase_22 AC 250 ms
11,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N = int(input())
Ws = list(map(int, input().split()))

w_sum = sum(Ws)
if w_sum % 2 != 0:
    print('impossible')
    sys.exit()

dp = [[True] + [False]*w_sum for i in range(N)]
for i in range(N):
    for j in range(w_sum+1):
        if dp[i-1][j]:
            dp[i][j] = True
        if j - Ws[i] < 0:
            continue
        if dp[i-1][j - Ws[i]]:
            dp[i][j] = True

if dp[-1][w_sum//2]:
    print('possible')
else:
    print('impossible')
0