結果

問題 No.740 幻の木
ユーザー taktak
提出日時 2019-02-08 14:37:48
言語 F#
(F# 4.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 5,653 ms
コンパイル使用メモリ 166,296 KB
実行使用メモリ 26,920 KB
最終ジャッジ日時 2023-09-10 10:57:22
合計ジャッジ時間 7,154 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
22,764 KB
testcase_01 AC 83 ms
22,924 KB
testcase_02 AC 83 ms
22,764 KB
testcase_03 AC 84 ms
24,956 KB
testcase_04 AC 83 ms
20,796 KB
testcase_05 AC 83 ms
22,756 KB
testcase_06 AC 147 ms
26,920 KB
testcase_07 AC 83 ms
22,884 KB
testcase_08 AC 82 ms
20,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

type Tree = { LeafNum: int; FallPerMonth: int }
type Time = { Month: int; Elapsed: int }
type Doing = { Tree: Tree; Time: Time }
type Done = { Elapsed: int }
type State = DOING of Doing | DONE of Done
type Environment = { WindyStart: int; WindySpan: int }
type Wind = Normal | Windy

let isWindy env month =
  if env.WindyStart <= month && month < env.WindyStart + env.WindySpan then Windy
  else Normal

let update env doing =
  
  let updateTree env month tree =
    match isWindy env month with
    | Windy  -> { tree with LeafNum = tree.LeafNum - tree.FallPerMonth * 2 }
    | Normal -> { tree with LeafNum = tree.LeafNum - tree.FallPerMonth }

  let updateTime time =
    match time with
    | { Month = 12 }-> { Month = 1; Elapsed = time.Elapsed + 1 }
    | _ -> { Month = time.Month + 1; Elapsed = time.Elapsed + 1 }

  let newTree = updateTree env doing.Time.Month doing.Tree
  let newTime = updateTime doing.Time

  match newTree with
  | { LeafNum = x } when x <= 0 -> DONE { Elapsed = newTime.Elapsed }
  | _ -> DOING { Tree = newTree; Time = newTime }

let simulate env tree = 
  let rec f state =
    match state with
    | DONE x -> x.Elapsed
    | DOING x -> f <| update env x
  f <| DOING { Tree = tree; Time = { Month = 1; Elapsed = 0 } }

let N, M, P, Q = 
  let t = stdin.ReadLine().Split() |> Array.map int
  t.[0], t.[1], t.[2], t.[3]

let tree = { LeafNum = N; FallPerMonth = M }
let environment = { WindyStart = P; WindySpan = Q }

simulate  environment tree 
|> printfn "%i"
0