結果

問題 No.113 宝探し
ユーザー tanson
提出日時 2025-08-26 01:06:03
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 817 bytes
コンパイル時間 4,300 ms
コンパイル使用メモリ 688,576 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-08-26 01:06:14
合計ジャッジ時間 5,800 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

exception WrongInput
fun findAns s =
    let
        val (x, y) =
            List.foldl
                (fn (ch, (x_acc, y_acc)) =>
                    case ch of
                        #"N" => (x_acc, y_acc - 1)
                      | #"E" => (x_acc + 1, y_acc)
                      | #"W" => (x_acc - 1, y_acc)
                      | #"S" => (x_acc, y_acc + 1)
                      | _ => raise WrongInput
                )
                (0, 0)
                (String.explode s)
    in
        Math.sqrt (Real.fromInt (x*x + y*y))
    end

val () =
    let
        val s = readStr ()
        val sWithoutCR = String.substring(s, 0, String.size s - 1)
        val ans = findAns sWithoutCR
    in
        print (Real.toString ans ^ "\n")  
    end
0