結果
| 問題 | No.227 簡単ポーカー |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-15 09:08:19 |
| 言語 | Standard ML (MLton 20241230) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,663 bytes |
| 記録 | |
| コンパイル時間 | 4,525 ms |
| コンパイル使用メモリ | 703,848 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-15 09:08:25 |
| 合計ジャッジ時間 | 4,480 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 |
ソースコード
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 fromList l =
List.foldl (fn (x, acc) =>
add acc x)
empty
l
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 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 [3, 2] = "FULL HOUSE"
| findAns (3::_) = "THREE CARD"
| findAns [2, 2, 1] = "TWO PAIR"
| findAns (2::_) = "ONE PAIR"
| findAns _ = "NO HAND"
val () =
let
val a1 = readInt ()
val a2 = readInt ()
val a3 = readInt ()
val a4 = readInt ()
val a5 = readInt ()
val bag = Bag.fromList [a1, a2, a3, a4, a5]
val cards = List.rev (quicksort (Bag.values bag))
val ans = findAns cards
in
print (ans ^ "\n")
end