結果

問題 No.4 おもりと天秤
ユーザー RyuRyu
提出日時 2018-05-07 23:25:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 17,304 KB
最終ジャッジ日時 2023-09-10 11:00:07
合計ジャッジ時間 3,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,908 KB
testcase_01 AC 22 ms
8,948 KB
testcase_02 AC 25 ms
9,020 KB
testcase_03 AC 23 ms
8,992 KB
testcase_04 AC 26 ms
9,104 KB
testcase_05 AC 154 ms
13,604 KB
testcase_06 AC 22 ms
8,980 KB
testcase_07 AC 156 ms
13,688 KB
testcase_08 AC 23 ms
8,908 KB
testcase_09 AC 269 ms
17,304 KB
testcase_10 AC 173 ms
14,216 KB
testcase_11 AC 23 ms
9,000 KB
testcase_12 AC 22 ms
8,952 KB
testcase_13 AC 23 ms
8,896 KB
testcase_14 AC 22 ms
8,968 KB
testcase_15 AC 22 ms
8,960 KB
testcase_16 AC 23 ms
9,004 KB
testcase_17 AC 21 ms
9,028 KB
testcase_18 AC 148 ms
13,028 KB
testcase_19 AC 144 ms
13,024 KB
testcase_20 AC 141 ms
13,100 KB
testcase_21 AC 133 ms
12,708 KB
testcase_22 AC 139 ms
13,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue


def main():
    n = int(input())

    w = list(map(int, input().split()))

    w_sum = sum(w)

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

    dp = [[False for _ in range(w_sum + 1)] for _ in range(n + 1)]

    dp[0][0] = True

    for i in range(n):
        for j in range(w_sum + 1):
            dp[i + 1][j] |= dp[i][j]
            if j + w[i] <= w_sum:
                dp[i + 1][j + w[i]] |= dp[i][j]

    print("possible" if dp[n][w_sum // 2] else "impossible")

    return


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