結果

問題 No.4 おもりと天秤
ユーザー トミートミー
提出日時 2024-03-26 02:12:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 609 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 67,924 KB
最終ジャッジ日時 2024-03-26 02:12:17
合計ジャッジ時間 2,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 36 ms
53,332 KB
testcase_02 WA -
testcase_03 AC 39 ms
59,636 KB
testcase_04 AC 43 ms
61,732 KB
testcase_05 AC 49 ms
63,768 KB
testcase_06 WA -
testcase_07 AC 50 ms
65,872 KB
testcase_08 AC 34 ms
53,332 KB
testcase_09 AC 58 ms
67,924 KB
testcase_10 AC 51 ms
63,768 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 40 ms
59,508 KB
testcase_17 AC 36 ms
53,332 KB
testcase_18 WA -
testcase_19 AC 51 ms
63,780 KB
testcase_20 AC 50 ms
63,780 KB
testcase_21 AC 72 ms
63,784 KB
testcase_22 AC 50 ms
63,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
w = list(map(int, input().split()))
if sum(w) % 2 == 1:
    print("impossible")
    exit()
else:
    div = int(sum(w)/2)
    # dp[i][j] i番目までのおもりをつかって重さjが作れるのか?
    dp = [[0 for j in range(div+1)] for i in range(n+1)]

    for i in range(1, n+1):
        if w[i-1] <= n:
            dp[i][w[i-1]] = 1
        for j in range(1, div+1):
            dp[i][j] = max(dp[i-1][j], dp[i][j])
            if w[i-1] < j:
                dp[i][j] = max(dp[i-1][j-w[i-1]], 1)

    if dp[n][div]:
        print("possible")
    else:
        print("impossible")
0