結果

問題 No.1535 五七五
ユーザー eseharaesehara
提出日時 2021-06-09 23:19:52
言語 OCaml
(5.1.0)
結果
RE  
実行時間 -
コード長 1,750 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 18,556 KB
実行使用メモリ 34,284 KB
最終ジャッジ日時 2023-08-19 09:33:35
合計ジャッジ時間 4,723 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

module Cp : sig
  val string_1_list_of_string: string -> string list
  val split_on_char: char -> string -> string list
  val read_int_list: unit -> int list
end =
struct
  let string_1_list_of_string x =
    String.to_seq x
    |> List.of_seq
    |> List.map (String.make 1);;

  let split_on_char sep s =
    (* from OCaml Standard Library 4.12 *)
    let r = ref [] in
    let j = ref (String.length s) in
    for i = String.length s - 1 downto 0 do
      if String.unsafe_get s i = sep then begin
        r := String.sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    String.sub s 0 !j :: !r;;

  let read_int_list () =
    read_line () |> split_on_char ' ' |> List.map int_of_string;;
end

let rec puyopuyo lst abc =
  match abc with
  | [] -> true
  | hd::tl ->
    match lst with
    | [] -> false
    | lhd::_ when hd < int_of_string lhd -> false
    | lhd::ltl when hd = int_of_string lhd -> puyopuyo ltl tl
    | lhd::ltl when hd > int_of_string lhd ->
      puyopuyo ltl ((hd - (int_of_string lhd)) :: tl)
    | _ -> failwith "WTF !!!! ( o____o ) !!!!"

let rec solve lst abc result =
  match lst with
  | [] -> failwith "WTF!!!"
  | _ when List.length lst < 3 -> result
  | _::tl ->
    if (puyopuyo lst abc)
    then solve tl abc (result + 1)
    else solve tl abc result;;

let rec start lst abc = solve lst abc 0;;

let rec length_of_string s =
  Cp.split_on_char ' ' s
  |> List.map String.length;;

let test_string = "kaeru pyoko pyoko mi pyoko pyoko awasete pyoko pyoko mu pyoko pyoko";;
let test_list = length_of_string test_string;;

let () =
  read_line () |> ignore;
  let abc = Cp.read_int_list () in
  let lst = Cp.split_on_char ' ' (read_line ()) in
  solve lst abc 0 |> print_int;
  print_newline ();;
0