結果

問題 No.4 おもりと天秤
ユーザー terrafarmterrafarm
提出日時 2020-12-14 08:02:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 20,080 KB
最終ジャッジ日時 2023-10-20 04:46:17
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
12,016 KB
testcase_01 AC 51 ms
12,016 KB
testcase_02 AC 53 ms
12,108 KB
testcase_03 AC 51 ms
12,040 KB
testcase_04 AC 53 ms
12,252 KB
testcase_05 AC 139 ms
16,296 KB
testcase_06 AC 51 ms
12,016 KB
testcase_07 AC 139 ms
16,332 KB
testcase_08 AC 53 ms
12,088 KB
testcase_09 AC 169 ms
20,080 KB
testcase_10 AC 149 ms
16,888 KB
testcase_11 AC 51 ms
12,024 KB
testcase_12 AC 52 ms
12,016 KB
testcase_13 AC 51 ms
12,016 KB
testcase_14 AC 51 ms
12,016 KB
testcase_15 AC 51 ms
12,016 KB
testcase_16 AC 51 ms
12,024 KB
testcase_17 AC 50 ms
12,016 KB
testcase_18 AC 122 ms
16,112 KB
testcase_19 AC 129 ms
15,948 KB
testcase_20 AC 128 ms
15,948 KB
testcase_21 AC 125 ms
15,684 KB
testcase_22 AC 127 ms
15,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import logging
import sys
from inspect import currentframe

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

logging.basicConfig(level=logging.DEBUG)


def dbg(*args):
    id2names = {id(v): k for k, v in currentframe().f_back.f_locals.items()}
    logging.debug(
        ", ".join(id2names.get(id(arg), "???") + " = " + repr(arg) for arg in args)
    )


def main():

    n = int(input())
    w = list(map(int, input().split()))
    sw = sum(w)
    dp = [[False] * (sw + 1) for _ in range(n + 1)]
    dp[0][0] = True
    for i in range(n):
        for j in range(sw, -1, -1):
            dp[i + 1][j] |= dp[i][j]
            if dp[i][j] and j + w[i] <= sw:
                dp[i + 1][j + w[i]] = True
    if sw % 2 != 0:
        print("impossible")
        exit()
    hw = sw // 2
    if dp[n][hw]:
        print("possible")
    else:
        print("impossible")


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