結果

問題 No.24 数当てゲーム
ユーザー tanson
提出日時 2025-08-19 23:21:11
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,692 bytes
コンパイル時間 3,114 ms
コンパイル使用メモリ 686,976 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-19 23:21:18
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun readStr () =
    valOf (TextIO.inputLine TextIO.stdIn)

fun readStrWithoutWS () =
    let
        val s = readStr ()
    in
        String.implode
            (List.filter
                 (fn c => Char.isAlphaNum c)
                 (String.explode s))
    end

fun readAction () =
    let
        val numbers = List.tabulate (4, fn _ => readInt ())
        val included = readStrWithoutWS ()
    in
        (numbers, included)
    end

fun member _ [] = false
  | member e (h::tl) = (e = h orelse member e tl)
                           

fun findAns actions =
    let
        val candidates = ref (List.tabulate (10, fn i => i))
    in
        (
          List.app
              (fn (numbers, included) =>
                  if included = "YES"
                  then
                      (
                        candidates :=
                        List.filter
                            (fn n =>
                                member n numbers)
                            (!candidates)
                      )
                  else
                      (
                        candidates :=
                        List.filter
                            (fn n =>
                                (member n numbers) = false)
                            (!candidates)
                      )
              )
              actions;
          List.hd (!candidates)
        )
    end

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

        val ans = findAns actions
    in
        print (Int.toString ans ^ "\n")
    end

0