結果

問題 No.4 おもりと天秤
ユーザー taisuketaisuke
提出日時 2023-02-19 18:24:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 192 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-09-27 22:58:36
合計ジャッジ時間 2,747 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,960 KB
testcase_01 AC 13 ms
8,068 KB
testcase_02 AC 15 ms
7,912 KB
testcase_03 AC 14 ms
7,804 KB
testcase_04 AC 14 ms
7,740 KB
testcase_05 AC 80 ms
7,804 KB
testcase_06 AC 12 ms
7,888 KB
testcase_07 AC 82 ms
7,824 KB
testcase_08 AC 13 ms
8,288 KB
testcase_09 AC 192 ms
8,304 KB
testcase_10 AC 91 ms
8,140 KB
testcase_11 AC 13 ms
7,784 KB
testcase_12 AC 13 ms
7,828 KB
testcase_13 AC 13 ms
7,844 KB
testcase_14 AC 12 ms
7,828 KB
testcase_15 AC 13 ms
7,820 KB
testcase_16 AC 14 ms
7,792 KB
testcase_17 AC 13 ms
7,836 KB
testcase_18 AC 83 ms
7,792 KB
testcase_19 AC 78 ms
7,784 KB
testcase_20 AC 70 ms
7,820 KB
testcase_21 AC 68 ms
7,816 KB
testcase_22 AC 66 ms
7,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

wmax = wsum // 2
dp = [False for j in range(wmax + 1)]
dp[0] = True

for i in range(1, n+1):
    tmp = dp.copy()
    for j in range(wmax + 1):
        if j >= w[i-1]:
            tmp[j] = tmp[j] or dp[j - w[i-1]]
    dp = tmp.copy()

ans = "possible" if dp[wmax] == True else "impossible"
print(ans)
0