結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,332 KB
testcase_01 AC 37 ms
53,332 KB
testcase_02 AC 42 ms
61,732 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 51 ms
65,876 KB
testcase_06 AC 34 ms
53,332 KB
testcase_07 AC 52 ms
65,876 KB
testcase_08 AC 35 ms
53,332 KB
testcase_09 AC 58 ms
65,824 KB
testcase_10 AC 53 ms
65,876 KB
testcase_11 AC 40 ms
59,636 KB
testcase_12 AC 34 ms
53,332 KB
testcase_13 AC 34 ms
53,332 KB
testcase_14 AC 34 ms
53,332 KB
testcase_15 AC 34 ms
53,332 KB
testcase_16 WA -
testcase_17 AC 33 ms
53,332 KB
testcase_18 AC 52 ms
65,876 KB
testcase_19 AC 51 ms
65,876 KB
testcase_20 AC 60 ms
63,776 KB
testcase_21 AC 51 ms
63,776 KB
testcase_22 AC 55 ms
63,776 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]], dp[i][j])

        

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