結果

問題 No.123 カードシャッフル
ユーザー r6ever6eve
提出日時 2017-08-10 16:15:51
言語 OCaml
(5.1.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 666 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 21,704 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 08:39:01
合計ジャッジ時間 948 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 15 ms
6,940 KB
testcase_11 AC 38 ms
6,940 KB
testcase_12 AC 27 ms
6,944 KB
testcase_13 AC 29 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let iota ?(start=0) ?(step=1) cnt =
  let rec doit i acc =
    if i <= 0 then acc
    else doit (i - 1) (start + step*(i - 1) :: acc) in
  doit cnt []

let () =
  let n, m = Scanf.scanf "%d %d " (fun n m -> n, m) in
  let l = iota ~start:1 n in
  let rec doit i l =
    if i = m then l
    else
      let a = Scanf.scanf "%d " (fun i -> i) in
      let a = a - 1 in
      let rec aux j xs = function
        | [] -> assert false
        | hd :: tl ->
          if j = a then hd :: List.rev_append xs tl
          else aux (j + 1) (hd :: xs) tl in
      aux 0 [] l |> doit (i + 1) in
  match doit 0 l with
  | [] -> assert false
  | hd :: _ -> Printf.printf "%d\n" hd
0