結果

問題 No.135 とりあえず1次元の問題
ユーザー tanson
提出日時 2025-08-29 01:06:02
言語 Standard ML
(MLton 20210117)
結果
TLE  
実行時間 -
コード長 1,072 bytes
コンパイル時間 3,074 ms
コンパイル使用メモリ 689,528 KB
実行使用メモリ 39,352 KB
最終ジャッジ日時 2025-08-29 01:06:14
合計ジャッジ時間 10,879 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 TLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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


fun quicksort [] = []
  | quicksort (h::tl) =
    let 
        val (s, b) =
            List.foldl
                (fn (x, (small, big)) =>
                    if x <= h then (x::small, big)
                    else (small, x::big))
                ([], [])
                tl
    in
        (quicksort s) @ [h] @ (quicksort 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 (quicksort 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