結果

問題 No.3397 Max Weighted Floor of Linear
コンテスト
ユーザー amentorimaru
提出日時 2025-11-30 18:26:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,152 bytes
記録
コンパイル時間 256 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 81,068 KB
最終ジャッジ日時 2025-12-03 23:36:56
合計ジャッジ時間 10,557 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 2 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
import math

def main():
  [n,m,a,b,c,d]=read_list()
  def calc(x):
    if x<0 or x >= n:
      return -10**17    
    return a*x+(c*x+d)//m*b
  # tmp=list()
  # for i in range(n):
  #   tmp.append(calc(i))
  # print(tmp)
  ans=list()
  ans.append(calc(0))
  ans.append(calc(n-1))
  if c==0:
    print(max(ans))
    return
  # 最初に上がる
  v0=(m-d-1)//c
  ans.append(calc(v0+1))
  ans.append(calc(v0))
  # 最後に上がる
  g=math.gcd(c,m)
  nv = ((n-1)*c+d)%m//c
  ans.append(calc(n-1-nv))
  ans.append(calc(n-2-nv))
  v=d%g
  # 最初にギリギリ上がる
  vv=pow(c//g,-1,m//g)*(m+v-d)%(m//g)
  ans.append(calc(vv))
  ans.append(calc(vv-1))
  # 最後にギリギリ上がる
  vv2=n//(m//g)*(m//g)+vv
  vv2+=m//g*5
  while vv2>=n:
    vv2-=m//g
  ans.append(calc(vv2))
  ans.append(calc(vv2-1))
  print(max(ans))
  return        
        
      
if __name__ == "__main__":
  t=int(input())
  for _ in range(t):
    main()
    
    
0