結果

問題 No.805 UMG
ユーザー eseharaesehara
提出日時 2021-06-11 12:15:00
言語 OCaml
(5.1.0)
結果
WA  
実行時間 -
コード長 2,389 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 20,096 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 11:14:58
合計ジャッジ時間 1,106 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
File "Main.ml", line 102, characters 8-20:
102 |     let start_string = read_line () in
              ^^^^^^^^^^^^
Warning 26 [unused-var]: unused variable start_string.

ソースコード

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

module BTS = struct
  let make_task work task_f =
    let (value ,rest) = work in
    match rest with
    | [] -> []
    | _ -> task_f value rest;;

  let rec start start_work task_f calc_f =
    let rec acc task result =
      match task with
      | [] -> result
      | work::rest ->
        let new_task = make_task work task_f in
        let result = calc_f work result in
        acc (new_task @ rest) result in
    let (value, rest) = start_work in
    acc (task_f value rest) 0;;
end

(*
define task_f function

task_f 'a -> 'b list -> 'c list
*)

let value_calc value workhd =
  match value with
  | "" when workhd = "U" -> "U"
  | "U" when workhd = "M" -> "M"
  | "M" when workhd = "G" -> "G"
  | _ -> value;;

let task_f value rest =
  let rec acc work rest result =
    match work with
    | [] -> result
    | _ when value = "G" -> result
    | hd::tl ->
      let next_value = value_calc value hd in
      let rest =
        if ((value = next_value) || (value = "G"))
        then [] else tl in
      acc tl rest ((next_value, rest)::result) in
  acc rest [] [];;

(*
define calc function

calc 'a * 'b list -> 'a -> 'a
*)

let calc_f work result =
  let (value, rest) = work in
  match rest with
  | [] -> if value = "G" then result + 1 else result
  | _ -> result;;

(*
define init_f
*)

let init_f str = ("", Cp.string_1_list_of_string str);;

let task_f_call task =
  let (task_v, task_r) = task in
  task_f task_v task_r;;
(*
Enjoy BTS CORE!

BTS.start (init_f "UUMGG") task_f calc_f;;
*)

let () =
    read_line () |> ignore;
    let start_string = read_line () in
    BTS.start (init_f "UUMGG") task_f calc_f 
    |> print_int;
    print_newline ();;
0