結果

問題 No.929 よくあるボールを移動するやつ
ユーザー pekempeypekempey
提出日時 2019-11-23 06:13:26
言語 OCaml
(5.1.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 400 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 21,576 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-17 08:51:00
合計ジャッジ時間 1,167 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 9 ms
5,888 KB
testcase_08 AC 18 ms
6,528 KB
testcase_09 AC 17 ms
6,400 KB
testcase_10 AC 17 ms
6,400 KB
testcase_11 AC 16 ms
6,400 KB
testcase_12 AC 16 ms
6,528 KB
testcase_13 AC 16 ms
6,528 KB
testcase_14 AC 16 ms
6,528 KB
testcase_15 AC 16 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

open Scanf ;;
open Printf ;;

let input_int () = scanf " %d" (fun x -> x) ;;
let input_ints n = Array.init n (fun _ -> input_int ()) ;;

let () =
  let n = input_int () in
  let b = input_ints n in
  let rec loop i s ans =
    if i = n then ans
    else begin
      let s' = s + b.(i) in
      let ans' = ans + abs (i - s) in
      loop (i + 1) s' ans'
    end
  in
  printf "%d\n" (loop 0 0 0)
  ;;
0