結果

問題 No.4 おもりと天秤
ユーザー taisuketaisuke
提出日時 2023-02-19 18:01:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 388 ms / 5,000 ms
コード長 462 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 12,380 KB
最終ジャッジ日時 2023-09-27 22:41:15
合計ジャッジ時間 3,510 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,812 KB
testcase_01 AC 16 ms
8,240 KB
testcase_02 AC 20 ms
7,856 KB
testcase_03 AC 17 ms
7,916 KB
testcase_04 AC 19 ms
8,192 KB
testcase_05 AC 176 ms
10,416 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 178 ms
10,456 KB
testcase_08 AC 14 ms
8,152 KB
testcase_09 AC 388 ms
12,380 KB
testcase_10 AC 212 ms
10,872 KB
testcase_11 AC 16 ms
7,900 KB
testcase_12 AC 15 ms
7,812 KB
testcase_13 AC 15 ms
7,844 KB
testcase_14 AC 15 ms
7,788 KB
testcase_15 AC 16 ms
8,008 KB
testcase_16 AC 17 ms
7,852 KB
testcase_17 AC 15 ms
7,848 KB
testcase_18 AC 187 ms
10,584 KB
testcase_19 AC 162 ms
10,152 KB
testcase_20 AC 163 ms
10,320 KB
testcase_21 AC 158 ms
10,012 KB
testcase_22 AC 161 ms
10,128 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 i in range(wmax + 1)] for j in range(n + 1)]
dp[0][0] = True

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

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