結果

問題 No.4 おもりと天秤
ユーザー 141sksk141sksk
提出日時 2019-07-23 19:33:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 12,312 KB
最終ジャッジ日時 2023-09-08 14:05:40
合計ジャッジ時間 2,283 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,808 KB
testcase_01 AC 16 ms
7,836 KB
testcase_02 AC 16 ms
7,708 KB
testcase_03 AC 16 ms
7,796 KB
testcase_04 AC 17 ms
8,184 KB
testcase_05 AC 57 ms
10,476 KB
testcase_06 AC 15 ms
7,836 KB
testcase_07 AC 56 ms
10,464 KB
testcase_08 AC 16 ms
7,844 KB
testcase_09 AC 96 ms
12,312 KB
testcase_10 AC 61 ms
10,784 KB
testcase_11 AC 16 ms
7,704 KB
testcase_12 AC 16 ms
7,784 KB
testcase_13 AC 16 ms
7,860 KB
testcase_14 AC 17 ms
7,776 KB
testcase_15 AC 16 ms
7,804 KB
testcase_16 AC 16 ms
7,840 KB
testcase_17 AC 16 ms
7,848 KB
testcase_18 AC 55 ms
10,424 KB
testcase_19 AC 51 ms
10,192 KB
testcase_20 AC 52 ms
10,168 KB
testcase_21 AC 49 ms
9,988 KB
testcase_22 AC 51 ms
10,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    W = list(map(int, input().split()))

    if sum(W) % 2 != 0:
        print("impossible")
    else:
        half = sum(W) // 2
        dp = [[0 for i in range(half + 1)] for j in range(N + 1)]
        dp[0][0] = 1
        for i in range(N):
            for j in range(half + 1):
                if W[i] <= j:
                    dp[i + 1][j] = dp[i][j - W[i]] or dp[i][j]
                else: 
                    dp[i + 1][j] = dp[i][j]          

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

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