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

Reflection

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

의견: 0

설명

Farmer John has a square canvas represented by an \(N\) by \(N\) grid of cells
(\(2 \leq N \leq 2000\), \(N\) is even). He paints the canvas according to the
following steps:

  1. First, he divides the canvas into four equal quadrants, separated by horizontal and vertical lines through the center of the canvas.
  2. Next, he paints a lovely painting in the top-right quadrant of the canvas. Each cell of the top-right quadrant will either be painted (represented by '#') or unpainted (represented by '.').
  3. Finally, since he is so proud of his painting, he reflects it across the previously mentioned horizontal and vertical lines into the other quadrants of the canvas.

For example, suppose \(N=8\) and FJ painted the following painting in the
top-right quadrant in step 2:

.#..
.#..
.##.
....

Then after reflecting across the horizontal and vertical lines into the other
quadrants in step 3, the canvas would look as follows:

..#..#..
..#..#..
.##..##.
........
........
.##..##.
..#..#..
..#..#..

However, while FJ was sleeping, Bessie broke into his barn and stole his
precious canvas. She totally vandalized the canvas—removing some painted cells
and adding more painted cells! Before FJ woke up, she returned the canvas to FJ.

FJ would like to modify his canvas so that it once again satisfies the
reflective condition: that is, it is the result of reflecting the top-right
quadrant into each of the other quadrants. Since he only has a limited number
of resources, he would like to achieve this in as few operations as possible,
where a single operation consists of either painting a cell or removing paint
from a cell.

You are given the canvas after Bessie's vandalism, as well as a sequence of \(U\)
(\(0\le U \leq 10^5\)) updates to the canvas, each toggling a single cell to '.'
if it is '#', or vice versa. Before any updates, and after each update, output
the minimum number of operations \(x\) FJ needs to perform so that the reflective
condition is satisfied.

Problem credits: Chongtian Ma

제약

SCORING

  • Inputs 2-3: \(N \le 4\)
  • Inputs 4-6: \(U \le 10\)
  • Inputs 7-16: No additional constraints.

Problem credits: Chongtian Ma

입력 형식

The first line contains integers \(N\) and \(U\).

The next \(N\) lines each contain \(N\) characters representing the canvas after
Bessie's vandalism. Every character is either '#' or '.'.

The following \(U\) lines each contain integers \(r\) and \(c\), where
\(1 \leq r, c \leq N\), representing an update to the cell in the \(r\)th row from
the top and \(c\)th column from the left of the canvas.

출력 형식

Output \(U+1\) lines representing \(x\) before any updates and after each update.

예제 1
입력
4 5
..#.
##.#
####
..##
1 3
2 3
4 3
4 4
4 4
출력
4
3
2
1
0
1
설명

The following canvas satisfies the reflective condition and differs from the
original canvas by 4 operations:

....
####
####
....

It is impossible to make the original canvas satisfy the reflective condition
using fewer than 4 operations.

After updating \((1, 3)\), the canvas looks like this:

....
##.#
####
..##

It now takes 3 operations to make the canvas satisfy the reflective condition.

After updating \((2, 3)\), the canvas looks like this:

....
####
####
..##

It now takes 2 operations to make the canvas satisfy the reflective condition.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > February > Bronze

태그

평가 및 의견

Reflection

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

Log in to rate problems.

개별 의견

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

풀이 제출

Reflection

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