提出 #346192
ソースコード 拡げる
let pf = Printf.printf ;;
let epf = Printf.eprintf ;;
let sf = Scanf.scanf ;;
let (|>) x f = f x ;;
let (@@) f x = f x ;;
module Array = struct
include ArrayLabels
let foldi ~f ~init arr =
let acc = ref init in
for i = 0 to Array.length arr - 1 do
acc := f i !acc arr.(i)
done;
!acc
;;
let findi arr ~f =
let len = Array.length arr in
let rec iter i =
if i = len then None
else if f arr.(i) then Some i
else iter (i + 1) in
iter 0
;;
let findi_exn arr ~f =
let len = Array.length arr in
let rec iter i =
if i = len then None
else if f arr.(i) then Some i
else iter (i + 1) in
iter 0
;;
(* i ∈ [0..res) -> not (f i) /\ i ∈ [res, len) -> f i *)
let lower_bound arr ~f =
let l, h = 0, Array.length arr in
(* res ∈ (l, h] *)
let rec iter l h =
if l = h - 1 then h
else
let m = (l + h) lsr 1 in
if f m then iter l m
else iter m h in
iter l h
;;
(* i ∈ [0..res] -> f i /\ i ∈ (res, len) -> not (f i) *)
let upper_bound arr ~f =
let l, h = 0, Array.length arr in
(* res ∈ [l, h) *)
let rec iter l h =
if l = h - 1 then l
else
let m = (l + h) lsr 1 in
if f m then iter m h
else iter l m in
iter l h
;;
end
module String = StringLabels ;;
module List = struct
include ListLabels ;;
let rec repeat n a = if n = 0 then [] else a :: repeat (n - 1) a ;;
let rec drop n a =
if n = 0 then a
else match a with
| [] -> failwith "cannot take"
| x :: xs -> drop (n - 1) xs ;;
let init ~f n =
let res = ref [] in
for i = 0 to n - 1 do
res := f i :: !res
done;
List.rev !res
;;
end ;;
module H = Hashtbl ;;
let c = ref ' ' ;;
let is_num c = '0' <= c && c <= '9' ;;
let is_space c = c = ' ' || c = '\n' || c = '\t' ;;
let to_num c = Char.code c - Char.code '0' ;;
let read_char () = input_char stdin ;;
let next_int () =
while is_space !c do
c := read_char () ;
done;
let ok = ref false in
let acc = ref 0 in
while is_num !c do
ok := true;
acc := !acc * 10 + to_num !c;
c := read_char ();
done;
if !ok then !acc
else raise (Failure "next_int")
;;
module SI = Set.Make (struct
type t = int
let compare = compare
end)
let split s =
let next i =
let c = s.[i] in
let rec iter i =
if i >= String.length s then i
else if s.[i] = c then iter (i + 1)
else i in
iter i in
let rec iter i =
if i >= String.length s then []
else
let j = next i in
String.make (j - i) s.[i] :: iter j in
iter 0
;;
let runlen s = Printf.sprintf "%c%d" s.[0] (String.length s) ;;
let solve s =
Printf.printf "%s\n" @@ (String.concat "" (split s |> List.map ~f:runlen))
;;
let () =
sf "%s" (fun s ->
solve s)
;;
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - 高橋くんと文字列圧縮 |
| ユーザ | iab |
| 言語 | OCaml (3.12.1) |
| 得点 | 100 |
| コード長 | 2989 Byte |
| 結果 | AC |
| 実行時間 | 34 ms |
| メモリ | 2972 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 100 / 100 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | subtask0_1.txt, subtask0_2.txt, subtask0_3.txt |
| All | 0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, subtask0_1.txt, subtask0_2.txt, subtask0_3.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0.txt | AC | 30 ms | 2964 KiB |
| 1.txt | AC | 31 ms | 2960 KiB |
| 10.txt | AC | 26 ms | 1172 KiB |
| 11.txt | AC | 26 ms | 1304 KiB |
| 12.txt | AC | 27 ms | 1304 KiB |
| 13.txt | AC | 26 ms | 1176 KiB |
| 14.txt | AC | 26 ms | 1172 KiB |
| 15.txt | AC | 26 ms | 1176 KiB |
| 16.txt | AC | 26 ms | 1220 KiB |
| 17.txt | AC | 26 ms | 1180 KiB |
| 18.txt | AC | 26 ms | 1176 KiB |
| 19.txt | AC | 27 ms | 1188 KiB |
| 2.txt | AC | 30 ms | 2964 KiB |
| 20.txt | AC | 26 ms | 1056 KiB |
| 21.txt | AC | 26 ms | 1048 KiB |
| 22.txt | AC | 25 ms | 1052 KiB |
| 23.txt | AC | 26 ms | 1052 KiB |
| 24.txt | AC | 26 ms | 1052 KiB |
| 25.txt | AC | 26 ms | 988 KiB |
| 26.txt | AC | 27 ms | 1052 KiB |
| 27.txt | AC | 26 ms | 1048 KiB |
| 28.txt | AC | 28 ms | 1048 KiB |
| 29.txt | AC | 28 ms | 1044 KiB |
| 3.txt | AC | 34 ms | 2964 KiB |
| 4.txt | AC | 32 ms | 2972 KiB |
| 5.txt | AC | 31 ms | 2968 KiB |
| 6.txt | AC | 31 ms | 2908 KiB |
| 7.txt | AC | 29 ms | 2908 KiB |
| 8.txt | AC | 29 ms | 2964 KiB |
| 9.txt | AC | 29 ms | 2836 KiB |
| subtask0_1.txt | AC | 26 ms | 1056 KiB |
| subtask0_2.txt | AC | 25 ms | 1048 KiB |
| subtask0_3.txt | AC | 25 ms | 988 KiB |