結果

問題 No.4 おもりと天秤
ユーザー taisuketaisuke
提出日時 2023-02-19 18:06:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 379 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,736 KB
実行使用メモリ 8,164 KB
最終ジャッジ日時 2023-09-27 22:43:52
合計ジャッジ時間 2,203 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,816 KB
testcase_01 AC 13 ms
8,120 KB
testcase_02 AC 18 ms
7,956 KB
testcase_03 AC 15 ms
7,808 KB
testcase_04 AC 15 ms
7,872 KB
testcase_05 AC 74 ms
7,912 KB
testcase_06 AC 13 ms
7,864 KB
testcase_07 AC 69 ms
7,784 KB
testcase_08 AC 13 ms
8,164 KB
testcase_09 AC 187 ms
7,872 KB
testcase_10 AC 78 ms
7,872 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 14 ms
7,740 KB
testcase_14 WA -
testcase_15 AC 14 ms
7,876 KB
testcase_16 AC 14 ms
7,820 KB
testcase_17 AC 14 ms
7,860 KB
testcase_18 AC 90 ms
7,740 KB
testcase_19 AC 64 ms
7,848 KB
testcase_20 AC 65 ms
7,832 KB
testcase_21 AC 67 ms
7,876 KB
testcase_22 AC 60 ms
7,864 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):
    for j in range(wmax + 1):
        if j >= w[i-1]:
            dp[j] = dp[j] or dp[j - w[i-1]]

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