結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,836 KB
testcase_01 AC 32 ms
9,968 KB
testcase_02 AC 33 ms
9,952 KB
testcase_03 AC 32 ms
9,880 KB
testcase_04 AC 34 ms
9,876 KB
testcase_05 AC 124 ms
11,768 KB
testcase_06 AC 31 ms
9,816 KB
testcase_07 AC 125 ms
11,788 KB
testcase_08 AC 32 ms
9,964 KB
testcase_09 AC 204 ms
13,676 KB
testcase_10 AC 137 ms
12,256 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 31 ms
9,988 KB
testcase_14 WA -
testcase_15 AC 32 ms
9,848 KB
testcase_16 AC 32 ms
9,876 KB
testcase_17 AC 31 ms
9,956 KB
testcase_18 AC 119 ms
11,880 KB
testcase_19 AC 115 ms
11,740 KB
testcase_20 AC 115 ms
11,876 KB
testcase_21 AC 109 ms
11,560 KB
testcase_22 AC 112 ms
11,572 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):
            dp[i][j] = dp[i-1][j]
            if j >= ws[i]:
                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