結果

問題 No.860 買い物
ユーザー pekempeypekempey
提出日時 2019-08-10 00:43:36
言語 OCaml
(5.1.0)
結果
AC  
実行時間 69 ms / 1,000 ms
コード長 651 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 21,452 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2024-04-17 08:48:32
合計ジャッジ時間 2,135 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 5 ms
5,888 KB
testcase_07 AC 68 ms
8,832 KB
testcase_08 AC 63 ms
8,960 KB
testcase_09 AC 63 ms
8,960 KB
testcase_10 AC 60 ms
8,832 KB
testcase_11 AC 53 ms
8,960 KB
testcase_12 AC 58 ms
8,960 KB
testcase_13 AC 63 ms
9,088 KB
testcase_14 AC 64 ms
8,960 KB
testcase_15 AC 42 ms
8,960 KB
testcase_16 AC 56 ms
8,960 KB
testcase_17 AC 69 ms
8,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

open Scanf
open Printf

let readint () = scanf " %d" (fun x -> x)
let readstr () = scanf " %s" (fun x -> x)
let readint2 () = scanf " %d %d" (fun x y -> x, y)
let stoa s = Array.init (String.length s) (String.get s)
let atos a = String.init (Array.length a) (Array.get a)

let inf = max_int / 4
let min3 x y z = min x (min y z)

let f (x, y, z) (c, d) =
  let x' = c + min3 (x + c) (y + c + d) (z + d) in
  let y' = c + min x (y + d) in
  let z' = c + min3 (x + c) (y + c + d) (z + d) in
  x', y', z'

let () =
  let n = readint () in
  let _, _, ans = Array.init n (fun _ -> readint2 ())
    |> Array.fold_left f (0, inf, inf) in
  printf "%d\n" ans
0