結果

問題 No.4 おもりと天秤
ユーザー shiccocsanshiccocsan
提出日時 2016-12-20 23:20:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 250 ms / 5,000 ms
コード長 513 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 10,908 KB
実行使用メモリ 15,604 KB
最終ジャッジ日時 2023-09-08 17:15:13
合計ジャッジ時間 3,190 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,080 KB
testcase_01 AC 16 ms
8,160 KB
testcase_02 AC 20 ms
7,888 KB
testcase_03 AC 17 ms
8,128 KB
testcase_04 AC 20 ms
8,180 KB
testcase_05 AC 158 ms
12,132 KB
testcase_06 AC 15 ms
7,768 KB
testcase_07 AC 146 ms
12,072 KB
testcase_08 AC 15 ms
8,180 KB
testcase_09 AC 250 ms
15,604 KB
testcase_10 AC 163 ms
12,872 KB
testcase_11 AC 17 ms
7,804 KB
testcase_12 AC 15 ms
7,724 KB
testcase_13 AC 16 ms
7,812 KB
testcase_14 AC 16 ms
7,904 KB
testcase_15 AC 16 ms
7,940 KB
testcase_16 AC 16 ms
8,100 KB
testcase_17 AC 15 ms
8,036 KB
testcase_18 AC 249 ms
11,860 KB
testcase_19 AC 128 ms
11,660 KB
testcase_20 AC 121 ms
11,592 KB
testcase_21 AC 124 ms
11,368 KB
testcase_22 AC 125 ms
11,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

n = input()
w = list(map(int, input().split()))
if sum(w) % 2 == 1:
    print("impossible")

    sys.exit()

w_div2 = sum(w) // 2
dp = [[0] * (w_div2 + 1) for i in range(len(w) + 1)]

for i in range(1, len(w)):
    for j in range(w_div2 + 1):
        if w[i - 1] <= j:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + w[i - 1])
        else:
            dp[i][j] = dp[i - 1][j]

        if dp[i][j] == w_div2:
            print("possible")
            sys.exit()
print("impossible")
0