Submission #52467430
Source Code Expand
let h, w, k = Scanf.scanf " %d %d %d" (fun i j k -> (i, j, k))
let s =
Array.init h @@ fun _ ->
Scanf.scanf " %s" Fun.id
let prefix_sum h w f =
let a =
Array.init h @@ fun _ ->
Array.init (w + 1) @@ fun _ ->
0 in
for i = 0 to h - 1 do
for j = 0 to w - 1 do
a.(i).(j + 1) <- a.(i).(j) + (if f (i, j) = 'o' then 1 else 0)
done
done;
a
let calc h w f =
let s = prefix_sum h w f in
let rec next p j = if j < w && not (p j) then next p (j + 1) else j in
let rec calc_row (i, j) c =
if j < w then begin
let l = next (fun j -> f (i, j) <> 'x') j in
let r = next (fun j -> f (i, j) = 'x') l in
Iter.(l -- (r - 1))
|> Iter.filter (fun j -> j + k <= r)
|> Iter.map (fun j -> k - (s.(i).(j + k) - s.(i).(j)))
|> Iter.iter c;
calc_row (i, r) c
end in
Iter.(0 -- (h - 1))
|> Iter.flat_map (fun i -> Iter.from_iter (calc_row (i, 0)))
|> Iter.fold Int.min Int.max_int
let () =
let t1 = calc h w (fun (i, j) -> s.(i).[j]) in
let t2 = calc w h (fun (i, j) -> s.(j).[i]) in
let t = Int.min t1 t2 in
let t = if t < Int.max_int then t else -1 in
Printf.printf "%d\n" t
Submission Info
| Submission Time | |
|---|---|
| Task | D - Cheating Gomoku Narabe |
| User | iwashisnake |
| Language | OCaml (ocamlopt 5.0.0) |
| Score | 400 |
| Code Size | 1212 Byte |
| Status | AC |
| Exec Time | 46 ms |
| Memory | 19560 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt, example3.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 2 ms | 4612 KiB |
| 001.txt | AC | 1 ms | 4584 KiB |
| 002.txt | AC | 1 ms | 4604 KiB |
| 003.txt | AC | 27 ms | 14964 KiB |
| 004.txt | AC | 27 ms | 14940 KiB |
| 005.txt | AC | 27 ms | 15012 KiB |
| 006.txt | AC | 29 ms | 14868 KiB |
| 007.txt | AC | 45 ms | 19412 KiB |
| 008.txt | AC | 46 ms | 19560 KiB |
| 009.txt | AC | 46 ms | 19428 KiB |
| 010.txt | AC | 46 ms | 19460 KiB |
| 011.txt | AC | 13 ms | 10068 KiB |
| 012.txt | AC | 12 ms | 10472 KiB |
| 013.txt | AC | 12 ms | 10084 KiB |
| 014.txt | AC | 18 ms | 11196 KiB |
| 015.txt | AC | 12 ms | 10132 KiB |
| 016.txt | AC | 16 ms | 10532 KiB |
| 017.txt | AC | 16 ms | 11616 KiB |
| 018.txt | AC | 17 ms | 10440 KiB |
| 019.txt | AC | 12 ms | 10116 KiB |
| 020.txt | AC | 16 ms | 10948 KiB |
| 021.txt | AC | 15 ms | 10020 KiB |
| 022.txt | AC | 15 ms | 10748 KiB |
| 023.txt | AC | 12 ms | 10584 KiB |
| 024.txt | AC | 15 ms | 10496 KiB |
| 025.txt | AC | 14 ms | 10344 KiB |
| 026.txt | AC | 14 ms | 10780 KiB |
| 027.txt | AC | 14 ms | 10228 KiB |
| 028.txt | AC | 16 ms | 9996 KiB |
| 029.txt | AC | 11 ms | 10116 KiB |
| 030.txt | AC | 13 ms | 10400 KiB |
| 031.txt | AC | 17 ms | 10608 KiB |
| 032.txt | AC | 12 ms | 10352 KiB |
| 033.txt | AC | 16 ms | 10320 KiB |
| 034.txt | AC | 14 ms | 10628 KiB |
| 035.txt | AC | 16 ms | 10260 KiB |
| 036.txt | AC | 12 ms | 10220 KiB |
| 037.txt | AC | 18 ms | 11380 KiB |
| 038.txt | AC | 12 ms | 10012 KiB |
| 039.txt | AC | 15 ms | 10228 KiB |
| 040.txt | AC | 13 ms | 10516 KiB |
| 041.txt | AC | 14 ms | 10564 KiB |
| 042.txt | AC | 12 ms | 10084 KiB |
| 043.txt | AC | 14 ms | 10196 KiB |
| 044.txt | AC | 12 ms | 10584 KiB |
| 045.txt | AC | 15 ms | 10276 KiB |
| 046.txt | AC | 11 ms | 10396 KiB |
| 047.txt | AC | 13 ms | 10028 KiB |
| 048.txt | AC | 17 ms | 10020 KiB |
| 049.txt | AC | 12 ms | 10024 KiB |
| 050.txt | AC | 17 ms | 10348 KiB |
| 051.txt | AC | 12 ms | 10140 KiB |
| 052.txt | AC | 15 ms | 10064 KiB |
| 053.txt | AC | 12 ms | 10032 KiB |
| 054.txt | AC | 15 ms | 10232 KiB |
| 055.txt | AC | 13 ms | 10596 KiB |
| 056.txt | AC | 16 ms | 10296 KiB |
| 057.txt | AC | 13 ms | 10660 KiB |
| 058.txt | AC | 14 ms | 10200 KiB |
| 059.txt | AC | 13 ms | 10832 KiB |
| 060.txt | AC | 14 ms | 10076 KiB |
| 061.txt | AC | 13 ms | 10212 KiB |
| 062.txt | AC | 14 ms | 10060 KiB |
| example0.txt | AC | 1 ms | 4760 KiB |
| example1.txt | AC | 1 ms | 4612 KiB |
| example2.txt | AC | 1 ms | 4656 KiB |
| example3.txt | AC | 1 ms | 4636 KiB |