結果

問題 No.887 Collatz
ユーザー guriceringuricerin
提出日時 2020-01-10 13:24:06
言語 F#
(F# 4.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 3,666 ms
コンパイル使用メモリ 163,876 KB
実行使用メモリ 25,144 KB
最終ジャッジ日時 2023-08-15 14:24:49
合計ジャッジ時間 8,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
25,104 KB
testcase_01 AC 86 ms
25,144 KB
testcase_02 AC 85 ms
23,012 KB
testcase_03 AC 85 ms
25,072 KB
testcase_04 AC 85 ms
23,128 KB
testcase_05 AC 85 ms
23,000 KB
testcase_06 AC 85 ms
23,220 KB
testcase_07 AC 85 ms
22,992 KB
testcase_08 AC 85 ms
23,012 KB
testcase_09 AC 84 ms
22,940 KB
testcase_10 AC 85 ms
22,996 KB
testcase_11 AC 86 ms
25,000 KB
testcase_12 AC 86 ms
25,040 KB
testcase_13 AC 85 ms
23,128 KB
testcase_14 AC 86 ms
24,976 KB
testcase_15 AC 85 ms
23,084 KB
testcase_16 AC 84 ms
23,024 KB
testcase_17 AC 85 ms
25,056 KB
testcase_18 AC 88 ms
25,060 KB
testcase_19 AC 85 ms
23,024 KB
testcase_20 AC 86 ms
22,956 KB
testcase_21 AC 86 ms
25,052 KB
testcase_22 AC 86 ms
20,944 KB
testcase_23 AC 86 ms
21,076 KB
testcase_24 AC 85 ms
25,144 KB
testcase_25 AC 85 ms
25,120 KB
testcase_26 AC 84 ms
23,016 KB
testcase_27 AC 85 ms
22,956 KB
testcase_28 AC 85 ms
23,024 KB
testcase_29 AC 85 ms
23,072 KB
testcase_30 AC 86 ms
21,076 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let solve() =
    let n = read int64

    let sq =
        seq {
            let mutable n = n
            while n <> 1L do
                yield n
                if (n &&& 1L) > 0L then n <- 3L * n + 1L else n <- n / 2L
            yield 1L
        }

    let ans =
        sprintf "%d\n%d" (Seq.length sq - 1) (Seq.max sq)

    puts ans
    ()

[<EntryPoint>]
let main _ =
    try
        solve()
    with e -> printfn "%s" (e.ToString())
    writer.Close()
    0 // return an integer exit code
0