結果

問題 No.4 おもりと天秤
ユーザー 炭酸水炭酸水
提出日時 2022-05-13 07:39:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 475 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-09-28 09:30:08
合計ジャッジ時間 1,945 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,836 KB
testcase_01 AC 14 ms
7,804 KB
testcase_02 AC 14 ms
7,752 KB
testcase_03 AC 13 ms
7,804 KB
testcase_04 AC 14 ms
7,768 KB
testcase_05 AC 81 ms
7,916 KB
testcase_06 AC 13 ms
7,960 KB
testcase_07 AC 88 ms
8,148 KB
testcase_08 AC 14 ms
7,840 KB
testcase_09 AC 56 ms
8,304 KB
testcase_10 AC 85 ms
8,260 KB
testcase_11 AC 13 ms
7,728 KB
testcase_12 AC 13 ms
7,912 KB
testcase_13 AC 13 ms
7,804 KB
testcase_14 AC 13 ms
7,768 KB
testcase_15 AC 17 ms
7,760 KB
testcase_16 AC 17 ms
7,804 KB
testcase_17 AC 14 ms
7,912 KB
testcase_18 AC 59 ms
8,216 KB
testcase_19 AC 76 ms
7,932 KB
testcase_20 AC 73 ms
7,908 KB
testcase_21 AC 73 ms
7,840 KB
testcase_22 AC 84 ms
7,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

w_sum = 0
for i in w:
    w_sum += i

if w_sum % 2 == 1:
    print("impossible")

elif w_sum % 2 == 0:
    dp = [False for _ in range(w_sum // 2 + 1)]
    dp[0] = True
    for i in range(n):
        dp_i = dp.copy()
        for j in range(w_sum // 2 + 1):
            if dp_i[j] and j + w[i] <= w_sum // 2:
                dp[j + w[i]] = True
    if dp[-1]:
        print("possible")
    else:
        print("impossible")
0