結果

問題 No.505 カードの数式2
コンテスト
ユーザー norioc
提出日時 2026-07-15 05:52:11
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 729 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 226 ms
コンパイル使用メモリ 96,116 KB
実行使用メモリ 370,028 KB
最終ジャッジ日時 2026-07-15 05:52:25
合計ジャッジ時間 8,744 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from itertools import pairwise


def accum_dp(xs: list, f, op, e, init: dict):
    dp = init.copy()
    for x in xs:
        pp = {}
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


def div(a, b):
    if (a < 0) ^ (b < 0):
        return -(-a // b)

    return a // b


def f(k, v, x):
    # k : 計算結果

    yield k+x, True
    yield k-x, True
    yield k*x, True

    if x != 0:
        yield div(k, x), True


INF = 1 << 62
N = int(input())
A = list(map(int, input().split()))

init = {A[0]: True}
dp = accum_dp(A[1:], f, max, -INF, init)

ans = max(dp.keys())
print(ans)
0