結果

問題 No.667 Mice's Luck(ネズミ達の運)
ユーザー taktak
提出日時 2018-04-12 15:50:58
言語 F#
(F# 4.0)
結果
AC  
実行時間 819 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 3,543 ms
コンパイル使用メモリ 160,496 KB
実行使用メモリ 34,416 KB
最終ジャッジ日時 2023-09-09 04:18:23
合計ジャッジ時間 8,460 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
26,904 KB
testcase_01 AC 84 ms
24,920 KB
testcase_02 AC 88 ms
24,816 KB
testcase_03 AC 87 ms
24,900 KB
testcase_04 AC 96 ms
26,944 KB
testcase_05 AC 161 ms
25,180 KB
testcase_06 AC 443 ms
31,700 KB
testcase_07 AC 819 ms
34,296 KB
testcase_08 AC 664 ms
34,416 KB
testcase_09 AC 548 ms
34,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

let (|Safe|Out|) = function | 'o' -> Safe | _ -> Out

let counter =
    Array.fold (fun acc c -> 
        match c with
        | Safe -> (fst acc + 1, snd acc    )        
        | _    -> (fst acc    , snd acc + 1)) (0,0)
                   
let calP (safeCnt,outCnt) = 
    let sCnt = safeCnt |> float
    let oCnt = outCnt  |> float
    let cntSum = sCnt + oCnt 
    if cntSum > 0.0 then sCnt / cntSum * 100.0
    else                 0.0
    
let S = stdin.ReadLine().ToCharArray() 
let cnts = S |> counter

S
|> Array.scan (fun acc x -> 
    match x with
    | Safe -> (fst acc - 1, snd acc    )
    | Out  -> (fst acc    , snd acc - 1)) cnts
|> Array.take (S.Length)
|> Array.map (calP)
|> Array.iter(printfn "%f")
0