RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0458

Paint by Letters

Diamond I 다이아몬드 I
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie has recently received a painting set. The canvas can be represented as an
\(N \times M\) rectangle of cells where the rows are labeled \(1\ldots N\) from top
to bottom and the columns are labeled \(1\ldots M\) from left to right
(\(1\le N,M\le 1000\)). Once painted, the color of a cell can be represented by an
uppercase letter from 'A' to 'Z.' Initially, all cells are uncolored, and a
cell cannot be painted more than once.

Bessie has specified the color that she desires for each cell. She can paint a
set of cells with a single color in one stroke if the set forms a connected
component, meaning that any cell in the set can reach any other via a sequence
of adjacent cells. Two cells are considered to be adjacent if they share an
edge.

For example, the \(3\times 3\) canvas

AAB
BBA
BBB

can be colored in four strokes as follows:

...    ..B    AAB    AAB    AAB
... -> ... -> ... -> BB. -> BBA
...    ...    ...    BBB    BBB

It is not possible to produce the end result using less than four strokes.

Being an avant-garde artist, Bessie will end up painting only a subrectangle of
the canvas. Currently, she is considering \(Q\) candidates (\(1\le Q\le 1000\)),
each of which can be represented by four integers \(x_1\), \(y_1\), \(x_2\), and
\(y_2.\) This means that the subrectangle consists of all cells with row in the
range \(x_1\) to \(x_2\) inclusive and column in the range \(y_1\) to \(y_2\) inclusive.

For each candidate subrectangle, what is the minimum number of strokes needed to
paint each cell in the subrectangle with its desired color while leaving all
cells outside the subrectangle uncolored? Note that Bessie does not actually do
any painting during this process, so the answers for each candidate are
independent.

Note: The time limit for this problem is 50 percent higher than the default,
and the memory limit is 512MB, twice the default.

Problem credits: Andi Qu

제약

SCORING

  • Test cases 1-2 satisfy \(N,M\le 50\).
  • In test cases 3-5, the canvas contains no cycles of a single color. That is, there does not exist a sequence of distinct cells \(c_1,c_2,c_3,\ldots,c_k\) such that all of the following conditions are satisfied:

\(k>2\)
- All of \(c_1,\ldots,c_k\) have the same desired color.
- \(c_i\) is adjacent to \(c_{i+1}\) for each \(1\le i.
- \(c_k\) is adjacent to \(c_1\).

Note that the \(3\times 3\) canvas above contains a cycle of a single color (the
four Bs in the bottom-left corner).In test cases 6-8, every connected component consisting of cells with the
same desired color can be contained within a two by two square with sides
parallel to the coordinate axes. The \(3\times 3\) canvas above does not satisfy
this property (the connected component with five Bs cannot be contained within a
two by two square).In test cases 9-11, every connected component consisting of cells with the
same desired color can be contained within a three by three square with sides
parallel to the coordinate axes. The \(3\times 3\) canvas above satisfies this
property.Test cases 12-20 satisfy no additional constraints.

Problem credits: Andi Qu

입력 형식

The first line contains \(N\), \(M\), and \(Q\).

The next \(N\) lines each contain a string of \(M\) uppercase characters
representing the desired colors for each row of the canvas.

The next \(Q\) lines each contain four space-separated integers \(x_1,y_1,x_2,y_2\)
representing a candidate subrectangle (\(1\le x_1\le x_2\le N\),
\(1\le y_1\le y_2\le M\)).

출력 형식

For each of the \(Q\) candidates, output the answer on a new line.

예제 1
입력
4 8 9
ABBAAAAA
ABAAAABA
CAADABBA
AAAAAAAA
1 1 4 8
3 5 3 8
1 3 2 4
1 4 2 5
1 1 3 3
4 4 4 4
2 6 4 8
3 5 4 6
1 6 3 8
출력
6
3
2
1
4
1
3
2
2
설명

The first candidate consists of the entire canvas, which can be painted in six
strokes.

The second candidate consists of the subrectangle with desired colors

ABBA

and can be colored in three strokes. Note that although the cells at \((3,5)\) and
\((3,8)\) can be colored with \(A\) in a single stroke if you consider the entire
canvas, this is not the case when considering only the cells within the
subrectangle.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2020-2021 > January > Platinum

태그

평가 및 의견

Paint by Letters

개요
출제자 난이도 Diamond I 다이아몬드 I 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Paint by Letters

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8