結果

問題 No.1663 Maximum Remainder
コンテスト
ユーザー tanson
提出日時 2026-02-05 01:23:57
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 959 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,838 ms
コンパイル使用メモリ 704,916 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-05 01:24:07
合計ジャッジ時間 5,090 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

fun printAns [] = ignore ()
  | printAns (h::tl) =
    let
        val hReal = Real.fromInt h
        val area = 3.0 * hReal * hReal * (Math.sqrt 3.0) / 4.0
    in
        (
          print (Real.toString area ^ "\n");
          printAns tl
        )
    end

fun findAns low high m acc =
    if low = high then Int.max(low mod m, acc)
    else
        (
          let
              val nextLow = low + 1
              val nextAcc = Int.max(low mod m, acc)
          in
              findAns nextLow high m nextAcc
          end
        )

val () =
    let
        val a = readInt ()
        val b = readInt ()
        val c = readInt ()
        val d = readInt ()
        val m = readInt ()

        val ans = if m <= (b + d) - (a + c) + 1 then m - 1
                  else findAns (a + c) (b + d) m 0
    in
        print (Int.toString ans ^ "\n")
    end
0