結果

問題 No.4 おもりと天秤
ユーザー ryusukeryusuke
提出日時 2022-02-20 18:53:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 493 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 84,792 KB
最終ジャッジ日時 2023-09-11 21:08:10
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
76,364 KB
testcase_01 AC 72 ms
71,244 KB
testcase_02 AC 87 ms
76,320 KB
testcase_03 AC 87 ms
76,008 KB
testcase_04 AC 87 ms
76,220 KB
testcase_05 AC 109 ms
76,068 KB
testcase_06 AC 78 ms
76,240 KB
testcase_07 AC 123 ms
84,792 KB
testcase_08 AC 70 ms
71,520 KB
testcase_09 AC 102 ms
76,332 KB
testcase_10 AC 110 ms
76,320 KB
testcase_11 AC 81 ms
76,180 KB
testcase_12 AC 78 ms
76,052 KB
testcase_13 AC 78 ms
76,132 KB
testcase_14 AC 80 ms
76,212 KB
testcase_15 AC 79 ms
76,228 KB
testcase_16 AC 81 ms
76,324 KB
testcase_17 AC 93 ms
76,280 KB
testcase_18 AC 106 ms
76,316 KB
testcase_19 AC 109 ms
76,348 KB
testcase_20 AC 107 ms
76,404 KB
testcase_21 AC 107 ms
76,252 KB
testcase_22 AC 109 ms
76,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if sum(w) % 2:
    print('impossible')
else:
    t = 10 ** 4 + 10
    dp = [[False] * t for _ in range(n + 1)]
    # dp[i][j] := i番目までの重りでjを作れるかどうか
    dp[0][0] = True
    for i in range(n):
        for j in range(t):
            if j - w[i] >= 0:
                dp[i + 1][j] |= dp[i][j - w[i]]
            dp[i + 1][j] |= dp[i][j]
    
    print('possible') if dp[-1][sum(w) // 2] else print('impossible')
0