結果

問題 No.4 おもりと天秤
ユーザー _manji0_manji0
提出日時 2022-01-14 01:47:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,205 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 45,532 KB
最終ジャッジ日時 2024-04-29 01:16:49
合計ジャッジ時間 17,789 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 509 ms
43,968 KB
testcase_01 AC 514 ms
43,844 KB
testcase_02 AC 523 ms
43,844 KB
testcase_03 AC 517 ms
43,708 KB
testcase_04 AC 525 ms
43,716 KB
testcase_05 AC 900 ms
44,004 KB
testcase_06 AC 512 ms
43,716 KB
testcase_07 AC 900 ms
43,752 KB
testcase_08 AC 508 ms
43,592 KB
testcase_09 AC 1,205 ms
45,532 KB
testcase_10 AC 938 ms
44,396 KB
testcase_11 AC 516 ms
43,708 KB
testcase_12 AC 558 ms
43,964 KB
testcase_13 AC 555 ms
43,580 KB
testcase_14 AC 549 ms
43,840 KB
testcase_15 AC 509 ms
43,712 KB
testcase_16 AC 514 ms
43,820 KB
testcase_17 AC 507 ms
43,580 KB
testcase_18 AC 873 ms
43,868 KB
testcase_19 AC 862 ms
43,588 KB
testcase_20 AC 863 ms
43,880 KB
testcase_21 AC 832 ms
43,464 KB
testcase_22 AC 843 ms
43,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy

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

    su = sum(W)

    if su % 2 == 1:
        print("impossible")
        return

    su = su // 2

    dp = numpy.zeros((N+1, su+1))

    for i in range(N+1):
        dp[i][0] = 1

    for j in range(1, su+1):
        dp[0][j] = 0


    for i in range(1, N+1):
        for j in range(1, su+1):
            w = W[i-1]

            if j-w < 0:
                dp[i][j] = 0
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]) * 1

    if dp[N][su]:
        print("possible")
    else:
        print("impossible")


if __name__ == "__main__":
    main()
0