結果
| 問題 |
No.930 数列圧縮
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-23 06:25:32 |
| 言語 | OCaml (5.2.1) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 857 bytes |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 21,576 KB |
| 実行使用メモリ | 10,236 KB |
| 最終ジャッジ日時 | 2024-10-09 00:51:52 |
| 合計ジャッジ時間 | 3,070 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
open Scanf ;;
open Printf ;;
exception Impossible ;;
let input_int () = scanf " %d" (fun x -> x) ;;
let input_ints n = List.init n (fun _ -> input_int ()) ;;
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