結果

問題 No.4 おもりと天秤
ユーザー human_cipherhuman_cipher
提出日時 2022-01-08 23:44:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 475 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 68,852 KB
最終ジャッジ日時 2024-04-26 19:32:51
合計ジャッジ時間 2,351 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,496 KB
testcase_01 AC 40 ms
51,700 KB
testcase_02 AC 45 ms
61,008 KB
testcase_03 AC 42 ms
60,616 KB
testcase_04 AC 45 ms
60,748 KB
testcase_05 AC 57 ms
65,516 KB
testcase_06 AC 38 ms
52,272 KB
testcase_07 AC 58 ms
66,288 KB
testcase_08 AC 38 ms
52,316 KB
testcase_09 AC 64 ms
68,852 KB
testcase_10 AC 59 ms
66,060 KB
testcase_11 AC 43 ms
60,348 KB
testcase_12 AC 38 ms
52,336 KB
testcase_13 AC 38 ms
52,936 KB
testcase_14 AC 42 ms
58,400 KB
testcase_15 AC 38 ms
53,216 KB
testcase_16 AC 41 ms
59,224 KB
testcase_17 AC 38 ms
52,184 KB
testcase_18 AC 56 ms
66,240 KB
testcase_19 AC 57 ms
65,912 KB
testcase_20 AC 56 ms
65,252 KB
testcase_21 AC 59 ms
66,880 KB
testcase_22 AC 56 ms
64,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

sumW = sum(W)
if sumW % 2 == 0:
    dp = [[False] * (sumW+1) for _ in range(n+1)]
    dp[0][0] = True
    for i in range(n):
        for j in range(sum(W)):
            if j - W[i] >= 0:
                dp[i+1][j] = dp[i][j] or dp[i][j-W[i]]
            else:
                dp[i+1][j] = dp[i][j]
    if dp[n][sumW//2]:
        ans = "possible"
    else:
        ans = "impossible"
else:
    ans = "impossible"
print(ans)
0