結果

問題 No.3397 Max Weighted Floor of Linear
コンテスト
ユーザー seekworser
提出日時 2025-11-29 03:17:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,128 bytes
記録
コンパイル時間 499 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 18,732 KB
最終ジャッジ日時 2025-12-03 23:36:50
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

INF = 10**2000
def solve():
    n, m, a, b, c, d = map(int, input().split())
    def eval(m, a, b, c, d, x: int) -> int:
        return a * x + b * ((c * x + d) // m)
    def f(n, m, a, b, c, d: int) -> int:
        if n <= 0: return -INF
        if c < 0 or d < 0:
            return f(n, m, a + b * (c // m), b, c % m, d % m) + b * (d // m)
        if a >= 0 and b >= 0: return eval(m, a, b, c, d, n-1)
        if a < 0 and b < 0: return eval(m, a, b, c, d, 0)
        if m == 1:
            return max(eval(m, a, b, c, d, 0), eval(m, a, b, c, d, n-1))
        if c >= m:
            c1 = c // m
            c2 = c % m
            return f(n, m, a + b * c1, b, c2, d)
        if d >= m:
            d1 = d // m
            d2 = d % m
            return f(n, m, a, b, c, d2) + b * d1
        k = (c * (n-1) + d) // m
        if a < 0:
            ans = f(k, c, b, a, m, m - d + c - 1) + b
            return max(ans, eval(m, a, b, c, d, 0))
        ans = f(k, c, b, a, m, m - d - 1)
        return max(ans, eval(m, a, b, c, d, n-1))
    ans = f(n, m, a, b, c, d)
    print(ans)

t = int(input())
for _ in range(t):
    solve()
0