結果

問題 No.740 幻の木
コンテスト
ユーザー tak
提出日時 2019-02-08 14:37:48
言語 F#
(F# 10.0)
コンパイル:
fsharp_c _filename_
実行:
/usr/bin/dotnet_wrap
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,498 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 17,605 ms
コンパイル使用メモリ 202,320 KB
実行使用メモリ 65,176 KB
最終ジャッジ日時 2026-03-16 11:53:11
合計ジャッジ時間 25,628 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (387 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net10.0/main.dll
  main -> /home/judge/data/code/bin/Release/net10.0/publish/

ソースコード

diff #
raw source code

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