結果
問題 |
No.930 数列圧縮
|
ユーザー |
|
提出日時 | 2019-11-23 06:26:16 |
言語 | OCaml (5.2.1) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 874 bytes |
コンパイル時間 | 451 ms |
コンパイル使用メモリ | 21,576 KB |
実行使用メモリ | 10,940 KB |
最終ジャッジ日時 | 2024-10-09 00:51:59 |
合計ジャッジ時間 | 3,025 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
open Scanf ;; open Printf ;; exception Impossible ;; let input_int () = scanf " %d" (fun x -> x) ;; let input_ints n = Array.init n (fun _ -> input_int ()) |> Array.to_list;; let rec last a = match a with | [] -> raise Impossible | [x] -> x | (x :: xs) -> last xs ;; let () = let n = input_int () in let a = input_ints n in if List.hd a > last a then print_endline "No" else begin print_endline "Yes"; let rec loop b = begin match b with | [] -> raise Impossible | (x :: []) -> [x] | (x :: y :: []) -> if x > y then raise Impossible else begin printf "%d " x; [y] end | (x :: y :: xs) -> if x < y then begin printf "%d " y; loop (x :: xs) end else loop (x :: loop (y :: xs)) end in loop a |> ignore end