結果

問題 No.701 ひとりしりとり
ユーザー taktak
提出日時 2018-06-16 08:52:22
言語 F#
(F# 4.0)
結果
AC  
実行時間 586 ms / 2,000 ms
コード長 1,471 bytes
コンパイル時間 4,888 ms
コンパイル使用メモリ 159,472 KB
実行使用メモリ 31,100 KB
最終ジャッジ日時 2023-09-13 05:57:04
合計ジャッジ時間 7,498 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
22,944 KB
testcase_01 AC 87 ms
24,948 KB
testcase_02 AC 84 ms
24,992 KB
testcase_03 AC 84 ms
25,132 KB
testcase_04 AC 84 ms
23,096 KB
testcase_05 AC 83 ms
23,016 KB
testcase_06 AC 84 ms
24,948 KB
testcase_07 AC 84 ms
24,880 KB
testcase_08 AC 84 ms
22,876 KB
testcase_09 AC 88 ms
21,028 KB
testcase_10 AC 132 ms
27,104 KB
testcase_11 AC 586 ms
31,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

let genSafeWord =
    let rec num2alp num =        
        match num with
        | 0   -> ""
        | num ->
            let alpSize   = ('z' |> int) - ('a' |> int)
            let alpOffset = ('a' |> int) - 1
            let n = 
                match num%alpSize with
                | 0 -> alpSize
                | n -> n
            let s = (n + alpOffset) |> char |> string
            match n with
            | x when x = num -> s
            | x              -> num2alp((num - n) / alpSize) + s   
    let cnt=ref 1 
    let genWord startCharacter =
        let newWord = startCharacter + (num2alp cnt.Value)
        incr cnt
        newWord                            
    (fun (preWord:string) ->
        let preLastCharacter = preWord.ToCharArray() |> Array.last |> string        
        let newWord = genWord preLastCharacter
        match newWord.ToCharArray()|> Array.last |> string with
        | "n" -> genWord preLastCharacter
        |  _  -> newWord)
        
let genOutWord (preWord:string) =
    let preLastCharacter = preWord.ToCharArray() |> Array.last |> string
    preLastCharacter + "n"
    

let n = stdin.ReadLine() |> int

Seq.unfold(fun (word,cnt)->    
    match cnt = (n-1) with
    | true -> 
        let nextWord = genOutWord word
        Some(word, (nextWord, cnt + 1))
    | _    ->
        let nextWord = genSafeWord word
        Some(word, (nextWord, cnt + 1))) ("a", 0)
|> Seq.skip 1
|> Seq.take n
|> Seq.iter(printfn "%s")    
0