結果
| 問題 | No.123 カードシャッフル |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-11-10 00:50:26 |
| 言語 | OCaml (5.2.1) |
| 結果 |
AC
|
| 実行時間 | 395 ms / 5,000 ms |
| コード長 | 975 bytes |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 19,584 KB |
| 実行使用メモリ | 13,696 KB |
| 最終ジャッジ日時 | 2024-10-08 23:55:27 |
| 合計ジャッジ時間 | 2,375 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 |
ソースコード
let shuffle card_lst a =
let rec shuffle' idx rest_lst head tail =
match rest_lst with
| [] -> head::tail
| x::xs ->
let head, tail =
if idx = a then (x, tail)
else (head, tail @ [x])
in
shuffle' (idx + 1) xs head tail
in
shuffle' 0 card_lst (-1) []
let solve n a_lst =
let card_lst = Array.init n (fun i -> i + 1) |>
Array.to_list
in
let rec solve' rest_lst result =
match rest_lst with
| [] -> result
| x::xs ->
let result = shuffle result (x - 1) in
solve' xs result
in
solve' a_lst card_lst |> List.hd
let read_int_int () =
read_line () |>
Str.split (Str.regexp_string " ") |>
List.map int_of_string |>
fun lst -> (List.nth lst 0, List.nth lst 1)
let () =
let n, _ = read_int_int ()
and a_lst = read_line () |>
Str.split (Str.regexp_string " ") |>
List.map int_of_string
in
solve n a_lst |> string_of_int |> print_endline