結果
| 問題 | No.123 カードシャッフル | 
| コンテスト | |
| ユーザー |  r6eve | 
| 提出日時 | 2017-08-10 16:15:51 | 
| 言語 | OCaml (5.2.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 38 ms / 5,000 ms | 
| コード長 | 666 bytes | 
| コンパイル時間 | 286 ms | 
| コンパイル使用メモリ | 21,580 KB | 
| 実行使用メモリ | 5,888 KB | 
| 最終ジャッジ日時 | 2024-10-09 00:09:26 | 
| 合計ジャッジ時間 | 988 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 10 | 
ソースコード
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
            
            
            
        