#P15663. [ICPC 2025 Jakarta R] International Olympiad in ICPC

[ICPC 2025 Jakarta R] International Olympiad in ICPC

题目描述

Your university is hosting a competition called the IOI. As an event organiser, you want to create a banner for it. The banner you are preparing can be represented as a 3×N3 \times N grid, where each cell will be printed either white or black. Due to printing issues, some of the cells cannot be printed in black.

You start with a white banner, and want to print the word IOI\texttt{IOI} on the banner as follows.

  • Form the first letter I\texttt{I} by printing a solid\textbf{solid} rectangle of size 3×p3 \times p (p1p \geq 1) in black.
  • Form the letter O\texttt{O} by printing a rectangular boundary\textbf{boundary} of size 3×q3 \times q (q3q \geq 3) in black.
  • Form the second letter I\texttt{I} by printing a solid\textbf{solid} rectangle of size 3×r3 \times r (r1r \geq 1) in black.

The letter O\texttt{O} must be formed between the letters I\texttt{I}, and there must be at least\textbf{at least} one column between the letters. It is also required that the width of the letter O\texttt{O} is at least\textbf{at least} the sum of the widths of the letters I\texttt{I}, i.e. qp+rq \geq p + r. All other cells not part of the word IOI\texttt{IOI} must remain white.

Determine the maximum number of cells that you can print in black, or tell that it's impossible to print the word IOI\texttt{IOI}.

输入格式

The first line contains an integer NN (1N200  0001 \le N \le 200\;000), the size of the 3×N3 \times N grid.

Each of the next three lines contains NN characters representing the cells of the grid.

Each of the 3N3N characters corresponds to a cell and is either .\texttt{.} or #\texttt{\#}, meaning you can or cannot print the cell in black, respectively.

输出格式

A single line representing the maximum number of cells that you can print in black.

If it's impossible to print the word IOI\texttt{IOI}, output 1-1 instead.

7
.......
.......
.......
14
6
......
......
......
-1
12
...#....#...
...#.##.#...
...#....#...
22
20
#...##..............
#...##.##....#...#..
#...##..............
39

提示

Explanation of Sample 1:\textit{Explanation of Sample 1:} You can print your banner in the following way.

  I.OOO.I
  I.O.O.I
  I.OOO.I

Explanation of Sample 3:\textit{Explanation of Sample 3:} You can print your banner in the following way.

  ..I#OOOO#III
  ..I#O##O#III
  ..I#OOOO#III

Explanation of Sample 4:\textit{Explanation of Sample 4:} You can print your banner in the following way.

  #III##OOOOOOOOOOO.II
  #III##O##....#..O#II
  #III##OOOOOOOOOOO.II