結果

問題 No.2208 Linear Function
コンテスト
ユーザー tanson
提出日時 2026-03-08 04:30:05
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 868 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,508 ms
コンパイル使用メモリ 704,776 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 04:30:12
合計ジャッジ時間 3,242 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fun readInt () =
    valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)


fun intString n =
    if 0 <= n
    then Int.toString n
    else "-" ^ Int.toString (abs n)

fun printList [] = ignore ()
  | printList (h :: tl) = 
    (
      print (intString h);
      print "\n";
      printList tl
    )


fun findMaxValue (l, r, a, b) =
    let
        fun findMaxValueAux i maxAcc =
            if r < i then maxAcc
            else findMaxValueAux (i + 1) (Int.max(a * i + b, maxAcc))
    in
        findMaxValueAux l (a * l + b)
    end


val () =
    let
        val t = readInt ()

        val cases = List.tabulate (t, fn _ => (readInt (), readInt (), readInt (), readInt ()))

        val ans = List.map (fn (l, r, a, b) =>
                               findMaxValue (l, r, a, b))
                           cases
    in
        printList ans
    end
0