結果

問題 No.4 おもりと天秤
ユーザー tmsausatmsausa
提出日時 2018-04-12 19:35:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 457 ms / 5,000 ms
コード長 520 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 16,184 KB
最終ジャッジ日時 2023-09-09 04:25:18
合計ジャッジ時間 5,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
8,468 KB
testcase_01 AC 16 ms
8,092 KB
testcase_02 AC 78 ms
9,380 KB
testcase_03 AC 59 ms
8,952 KB
testcase_04 AC 78 ms
9,304 KB
testcase_05 AC 389 ms
16,060 KB
testcase_06 AC 25 ms
8,400 KB
testcase_07 AC 415 ms
16,032 KB
testcase_08 AC 15 ms
8,288 KB
testcase_09 AC 457 ms
16,044 KB
testcase_10 AC 409 ms
15,912 KB
testcase_11 AC 44 ms
8,676 KB
testcase_12 AC 29 ms
8,544 KB
testcase_13 AC 30 ms
8,464 KB
testcase_14 AC 33 ms
8,600 KB
testcase_15 AC 29 ms
8,420 KB
testcase_16 AC 54 ms
8,896 KB
testcase_17 AC 48 ms
8,672 KB
testcase_18 AC 400 ms
15,972 KB
testcase_19 AC 395 ms
16,148 KB
testcase_20 AC 391 ms
16,184 KB
testcase_21 AC 426 ms
16,080 KB
testcase_22 AC 387 ms
16,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
weights_list = [0] + list(map(int, input().split(' ')))

total = sum(weights_list)
if total % 2 == 1:
    print("impossible")
    exit()

#dp = np.zeros((N + 1, 10001), dtype=np.bool)
dp = [[0] * (10001) for _ in range(N + 1)]

dp[0][0] = True
for i in range(1, N + 1):
    for j in range(10001):
        if (dp[i-1][j] == True) or ((j >= weights_list[i]) and (dp[i-1][j-weights_list[i]] == True)):
            dp[i][j] = True

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