結果

問題 No.135 とりあえず1次元の問題
ユーザー tanson
提出日時 2025-08-29 01:10:36
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 1,178 bytes
コンパイル時間 2,999 ms
コンパイル使用メモリ 687,228 KB
実行使用メモリ 39,356 KB
最終ジャッジ日時 2025-08-29 01:10:43
合計ジャッジ時間 6,434 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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


fun quicksortNoDuplicate [] = []
  | quicksortNoDuplicate (h::tl) =
    let 
        val (s, b) =
            List.foldl
                (fn (x, (small, big)) =>
                    if x = h then (small, big)
                    else if x < h then (x::small, big)
                    else (small, x::big))
                ([], [])
                tl
    in
        (quicksortNoDuplicate s) @ [h] @ (quicksortNoDuplicate b)
    end


fun findAns l =
    let
        fun findAnsLoop [] min = min
          | findAnsLoop [_] min = min 
          | findAnsLoop (h1 :: h2 :: tl) min =
            if h1 = h2 then findAnsLoop (h2 :: tl) min
            else if h2 - h1 < min then findAnsLoop (h2 :: tl) (h2 - h1)
            else findAnsLoop (h2 :: tl) min

        val limit = 9999999

        val ans = findAnsLoop (quicksortNoDuplicate l) limit
    in
        if ans = limit then 0
        else ans
    end


val () =
    let
        val n = readInt ()
        val x_s = List.tabulate (n, fn _ => readInt ())
        val ans = findAns x_s
    in
        print (Int.toString ans ^ "\n")
    end
0