結果

問題 No.4 おもりと天秤
ユーザー kazz4423kazz4423
提出日時 2017-07-22 22:42:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 778 ms / 5,000 ms
コード長 726 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 78,468 KB
最終ジャッジ日時 2023-09-08 17:32:36
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,912 KB
testcase_01 AC 16 ms
7,872 KB
testcase_02 AC 24 ms
9,036 KB
testcase_03 AC 18 ms
8,384 KB
testcase_04 AC 24 ms
9,192 KB
testcase_05 AC 415 ms
44,772 KB
testcase_06 AC 16 ms
7,808 KB
testcase_07 AC 418 ms
44,988 KB
testcase_08 AC 15 ms
7,912 KB
testcase_09 AC 778 ms
78,468 KB
testcase_10 AC 453 ms
48,396 KB
testcase_11 AC 16 ms
8,464 KB
testcase_12 AC 15 ms
7,856 KB
testcase_13 AC 16 ms
7,964 KB
testcase_14 AC 16 ms
7,968 KB
testcase_15 AC 16 ms
7,808 KB
testcase_16 AC 16 ms
8,316 KB
testcase_17 AC 16 ms
7,968 KB
testcase_18 AC 386 ms
43,824 KB
testcase_19 AC 362 ms
42,160 KB
testcase_20 AC 375 ms
41,892 KB
testcase_21 AC 355 ms
40,900 KB
testcase_22 AC 347 ms
41,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = [int(i) for i in input().split()]

sW = list(reversed(sorted(W)))
target = int(sum(W)/2)
dp ={}
if sum(W)%2 ==0:

    if sW[0] == target: # 最大値がそのままターゲットなら”可能”
        print("possible")
    else:
        for j in range(int(target)+1):
            dp[(N-1,j)] = 0
        for i in reversed(range(N-1)):
            for j in range(int(target)+1):
                if (j < W[i]):
                    dp[(i,j)] = dp[(i+1, j)]
                else:
                    dp[(i,j)] = max(dp[(i+1, j)], dp[(i+1, j - W[i])]+W[i])
        if target == dp[(0,int(target))]:
            print("possible")
        else:
            print("impossible")

else:
    print("impossible")
0