結果

問題 No.4 おもりと天秤
ユーザー yassu0320yassu0320
提出日時 2021-07-11 12:19:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,262 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 11,032 KB
実行使用メモリ 13,716 KB
最終ジャッジ日時 2023-09-14 20:08:32
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,836 KB
testcase_01 AC 32 ms
9,768 KB
testcase_02 AC 34 ms
9,816 KB
testcase_03 AC 35 ms
9,844 KB
testcase_04 AC 33 ms
9,952 KB
testcase_05 AC 123 ms
11,836 KB
testcase_06 AC 31 ms
9,884 KB
testcase_07 AC 123 ms
11,852 KB
testcase_08 AC 31 ms
9,804 KB
testcase_09 AC 199 ms
13,716 KB
testcase_10 AC 135 ms
12,288 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 31 ms
9,972 KB
testcase_14 WA -
testcase_15 AC 31 ms
9,900 KB
testcase_16 AC 32 ms
9,820 KB
testcase_17 AC 32 ms
9,900 KB
testcase_18 AC 119 ms
11,728 KB
testcase_19 AC 113 ms
11,772 KB
testcase_20 AC 114 ms
11,772 KB
testcase_21 AC 109 ms
11,556 KB
testcase_22 AC 110 ms
11,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

from sys import setrecursionlimit, stdin
from typing import Dict, Iterable, Set

INF: int = 2**62
MOD: int = 10**9 + 7

setrecursionlimit(10**6)


def inputs(type_=int):
    ins = input().split(' ')
    ins = [x for x in ins if x != '']

    if isinstance(type_, Iterable):
        return [t(x) for t, x in zip(type_, ins)]
    else:
        return list(map(type_, ins))


def input_(type_=int):
    a, = inputs(type_)
    return a


inputi = input_


def inputstr():
    return input_(str)


# b/aの切り上げ
def ceil(b, a):
    return (a + b - 1) // a


def answer(res) -> None:
    print(res)
    exit()


def compute():
    return


def main():
    n = inputi()
    ws = inputs()
    if sum(ws) %2 == 1:
        print('impossible')
        exit()
    target = sum(ws) // 2
    ws = [0] + ws
    n += 1

    dp = [[False] * (target+1) for _ in range(n)]
    dp[0][0] = True

    for i in range(1, n):
        for j in range(target + 1):
            if j >= ws[i] and j - ws[i] <= target:
                dp[i][j] = max(dp[i-1][j], dp[i][j-ws[i]])
            else:
                dp[i][j] = dp[i-1][j]

    if dp[-1][target]:
        print('possible')
    else:
        print('impossible')


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