結果

問題 No.930 数列圧縮
ユーザー pekempeypekempey
提出日時 2019-11-23 06:26:16
言語 OCaml
(5.1.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 874 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2024-04-17 08:51:32
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 35 ms
7,936 KB
testcase_09 AC 41 ms
8,320 KB
testcase_10 AC 33 ms
7,808 KB
testcase_11 AC 38 ms
7,808 KB
testcase_12 AC 41 ms
8,320 KB
testcase_13 AC 14 ms
6,400 KB
testcase_14 AC 15 ms
6,144 KB
testcase_15 AC 50 ms
8,832 KB
testcase_16 AC 52 ms
10,832 KB
testcase_17 AC 50 ms
8,832 KB
testcase_18 AC 51 ms
8,704 KB
testcase_19 AC 50 ms
8,704 KB
testcase_20 AC 51 ms
8,832 KB
testcase_21 AC 50 ms
8,832 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 51 ms
8,704 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0