結果
| 問題 | No.3397 Max Weighted Floor of Linear |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2025-11-18 17:51:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 922 bytes |
| 記録 | |
| コンパイル時間 | 253 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 18,340 KB |
| 最終ジャッジ日時 | 2025-12-03 23:32:58 |
| 合計ジャッジ時間 | 5,914 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 21 |
ソースコード
# 解答例(Python3/PyPy3) mwf(L,R,m,a,b,c,d) = max_{x in [L,R)} (a*x + b*floor((c*x + d)/m))
def mwf(L: int, R: int, m: int, a: int, b: int, c: int, d: int) -> int:
assert L < R and 0 < m
n = R - L
qd0, d = divmod(c * L + d, m)
max_acc = sum_acc = a * L + b * qd0
while True:
qc, c = divmod(c, m)
a += b * qc
qd, d = divmod(d, m)
sum_acc += b * qd
y_max = (c * (n - 1) + d) // m
max_acc = max(max_acc, sum_acc, sum_acc + a * (n - 1) + b * y_max)
if y_max == 0 or (a >= 0 and b >= 0) or (a <= 0 and b <= 0):
return max_acc
if a < 0:
sum_acc += a + b
n, m, a, b, c, d = y_max, c, b, a, m, (m - d - 1)
if __name__ == "__main__":
import sys
T = int(sys.stdin.readline())
for _ in range(T):
N, M, A, B, C, D = map(int, sys.stdin.readline().split())
print(mwf(0, N, M, A, B, C, D))