結果

問題 No.930 数列圧縮
コンテスト
ユーザー pekempey
提出日時 2019-11-23 06:25:32
言語 OCaml
(5.5.0)
コンパイル:
ocamlfind ocamlopt -linkpkg -package zarith,str _filename_ -o a.out
実行:
./a.out
結果
AC  
実行時間 31 ms / 2,000 ms
+ 497µs
コード長 857 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 123 ms
コンパイル使用メモリ 22,564 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2026-09-12 07:31:05
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
ocamlfind: [WARNING] Cannot read directory ./stublibs which is mentioned in ld.conf

ソースコード

diff #
raw source code

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
0