結果

問題 No.930 数列圧縮
ユーザー pekempeypekempey
提出日時 2019-11-23 06:25:32
言語 OCaml
(5.1.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 21,448 KB
実行使用メモリ 10,236 KB
最終ジャッジ日時 2024-04-17 08:51:29
合計ジャッジ時間 3,212 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 2 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 36 ms
7,296 KB
testcase_09 AC 42 ms
7,552 KB
testcase_10 AC 35 ms
7,296 KB
testcase_11 AC 37 ms
7,552 KB
testcase_12 AC 43 ms
7,552 KB
testcase_13 AC 16 ms
6,912 KB
testcase_14 AC 19 ms
6,912 KB
testcase_15 AC 51 ms
8,192 KB
testcase_16 AC 54 ms
10,236 KB
testcase_17 AC 50 ms
8,192 KB
testcase_18 AC 51 ms
8,192 KB
testcase_19 AC 50 ms
8,192 KB
testcase_20 AC 52 ms
8,192 KB
testcase_21 AC 48 ms
8,192 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 50 ms
8,064 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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