結果

問題 No.182 新規性の虜
コンテスト
ユーザー tanson
提出日時 2026-05-06 00:36:59
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
TLE  
実行時間 -
コード長 1,091 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,863 ms
コンパイル使用メモリ 705,212 KB
実行使用メモリ 38,988 KB
最終ジャッジ日時 2026-05-06 00:37:38
合計ジャッジ時間 10,241 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

structure Bag =
struct
datatype 'a tree = Leaf | Node of 'a * int * 'a tree * 'a tree

val empty = Leaf

fun size Leaf = 0
  | size (Node (k, v, left, right)) = 1 + size left + size right

fun add Leaf newKey = Node (newKey, 1, Leaf, Leaf)
  | add (Node (nodeKey, nodeValue, left, right)) newKey =
    if nodeKey = newKey then (Node (nodeKey, nodeValue + 1, left, right))
    else if nodeKey < newKey then Node (nodeKey, nodeValue, left, add right newKey)
    else Node (nodeKey, nodeValue, add left newKey, right)

fun values Leaf = []
  | values (Node (_, v, left, right)) = [v] @ values left @ values right

end


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


fun makeBag l =
    List.foldl (fn (a, acc) =>
                   Bag.add acc a)
               Bag.empty
               l

val () =
    let
        val n = readInt ()
        val a_s = List.tabulate (n, fn _ => readInt ())

        val bag = makeBag a_s
        val ans = List.length (List.filter (fn v => v = 1) (Bag.values bag))
    in
        print (Int.toString ans ^ "\n")
    end
0