結果

問題 No.3397 Max Weighted Floor of Linear
コンテスト
ユーザー 👑 Mizar
提出日時 2025-12-07 01:56:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 754 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 380 ms
コンパイル使用メモリ 82,676 KB
実行使用メモリ 94,148 KB
最終ジャッジ日時 2025-12-07 01:57:14
合計ジャッジ時間 24,498 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-


def mwf(n: int, m: int, a: int, b: int, c: int, d: int) -> int:
    assert n > 0 and m > 0
    q, c = divmod(c, m)
    a += b * q
    q, d = divmod(d, m)
    s = b * q
    assert 0 <= c < m and 0 <= d < m
    y_max = (c * (n - 1) + d) // m
    return max(s, s + a * (n - 1)) if y_max == 0 else max(
        s,
        s + a * (n - 1) + b * y_max,
        s + (a + b) * (a < 0) + mwf(y_max, c, b, a, m, (m - d - 1))
    )


def solve():
    import sys
    input = sys.stdin.readline

    T = int(input())
    for _ in range(T):
        N, M, A, B, C, D = map(int, input().split())
        assert 0 < N and 0 < M
        ans = mwf(N, M, A, B, C, D)
        print(ans)


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