結果

問題 No.1037 exhausted
ユーザー ikdikd
提出日時 2020-05-02 13:54:00
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 1,815 bytes
コンパイル時間 8,495 ms
コンパイル使用メモリ 201,184 KB
実行使用メモリ 98,376 KB
最終ジャッジ日時 2024-06-09 12:11:26
合計ジャッジ時間 15,396 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
35,072 KB
testcase_01 AC 63 ms
36,992 KB
testcase_02 AC 313 ms
35,232 KB
testcase_03 AC 64 ms
31,868 KB
testcase_04 AC 303 ms
35,492 KB
testcase_05 AC 67 ms
31,488 KB
testcase_06 AC 312 ms
35,608 KB
testcase_07 WA -
testcase_08 AC 619 ms
54,912 KB
testcase_09 WA -
testcase_10 AC 304 ms
35,532 KB
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (217 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
/home/judge/data/code/Main.fs(22,18): warning FS0025: この式のパターン マッチが不完全です たとえば、値 '[|_; _; _; _|]' はパターンに含まれないケースを示す可能性があります。 [/home/judge/data/code/main.fsproj]
/home/judge/data/code/Main.fs(18,9): warning FS0025: この式のパターン マッチが不完全です たとえば、値 '[|_; _; _; _|]' はパターンに含まれないケースを示す可能性があります。 [/home/judge/data/code/main.fsproj]
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

// Learn more about F# at http://fsharp.org

open System

type S =
    { X: int
      V: int
      W: int64 }

let min a b =
    if a < b then a else b

let max a b =
    if a > b then a else b

[<EntryPoint>]
let main argv =
    let [| n; v; l |] = stdin.ReadLine().Split() |> Array.map int

    let mutable stands =
        [| for i in 1 .. n ->
            (let [| x; v; w |] = stdin.ReadLine().Split() |> Array.map int
             { X = x
               V = v
               W = w |> int64 }) |]
    if stands.[0].X > 0 then
        stands <-
            Array.append
                [| { X = 0
                     V = 0
                     W = 0 |> int64 } |] stands
    if stands.[stands.Length - 1].X < l then
        stands <-
            Array.append stands
                [| { X = l
                     V = 0
                     W = 0 |> int64 } |]
    let nn = stands.Length
    let inf = Int64.MaxValue / 2L
    let mutable memo = Array2D.create (nn + 1) (v + 1) inf
    // printfn "%A" stands
    let rec solve i j =
        // printfn "%A %A" i j
        if memo.[i, j] < inf then
            memo.[i, j]
        else if i = 0 then
            memo.[i, j] <- if j = v then 0L else inf
            memo.[i, j]
        else
            let mutable res = inf
            let d = stands.[i].X - stands.[i - 1].X
            if j + d <= v then res <- min res (solve (i - 1) (j + d))
            for k = (j - 1) downto (max 0 (j - stands.[i].V)) do
                res <- min res ((solve i k) + stands.[i].W)
            memo.[i, j] <- res
            memo.[i, j]

    let mutable ans = inf
    for j = 0 to v do
        ans <- min ans (solve (nn - 1) j)
    if ans < inf then printfn "%d" ans else printfn "-1"
    // printfn "%A" memo
    // printfn "%A" stands
    0 // return an integer exit code
0