QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#20127. 정복 작전

Statistics

30세기 초부터 Country of Circles는 세계에서 가장 강력한 국가가 되었습니다. 서쪽으로 영토를 확장하기 위해 Country of Rectangles를 침공할 계획입니다.

Country of Rectangles의 영토는 $R\times C$ 표로 나타내며, 행에는 $1$부터 $R$까지, 열에는 $1$부터 $C$까지 번호가 붙습니다. $i$번째 행, $j$번째 열의 칸을 $(i,j)$로 나타냅니다.

Country of Circles의 국방부는 정예 공수부대로 Country of Rectangles를 공격할 계획입니다. 상대국에 첩자를 보내, Country of Rectangles의 $N$개 칸 $(x_1,y_1),(x_2,y_2),\ldots,(x_N,y_N)$이 매우 허술하게 방어되어 쉽게 점령할 수 있음을 알아냈습니다. 따라서 다음 계획을 세웠습니다.

  • 첫날에는 이 $N$개 칸 각각을 점령하기 위해 공수부대 한 대대를 보냅니다.
  • 이후 매일, 이전에 점령한 칸 중 하나 이상과 변을 공유하는 모든 칸을 점령하도록 증원군을 보냅니다.

Country of Circles의 군대는 원하는 어떤 칸이든 점령할 만큼 강하다고 가정합니다.

지휘관은 나라 전체를 정복하는 데 며칠이 걸리는지 알고 싶어 합니다.

입력

  • 첫째 줄에는 세 정수 $R$, $C$, $N$ ($1\le R,C\le100$, $1\le N\le10\,000$)이 주어집니다. 각각 Country of Rectangles 영토의 행 수, 열 수, 방어가 허술한 칸의 수입니다. 이 칸들이 서로 다름은 보장되지 않습니다.
  • 다음 $N$개 줄 중 $i$번째 줄에는 두 정수 $x_i$, $y_i$ ($1\le x_i\le R$, $1\le y_i\le C$)가 주어집니다. 이는 작전 첫날 공수부대를 보내는 칸 하나를 나타냅니다.

출력

Country of Circles가 Country of Rectangles를 완전히 정복하는 데 필요한 날짜 수를 나타내는 수 하나를 정확히 출력하세요.

예제

입력 1

3 4 3
2 2
2 2
3 4

출력 1

3

참고

아래 그림은 각 날짜에 계획이 어떻게 실행되는지 보여 줍니다.

  • 점령하지 않은 칸은 흰색입니다.
  • 이날 점령한 칸은 줄무늬로 채워져 있습니다.
  • 이전 날짜에 점령한 칸은 단색으로 채워져 있습니다.
problem_20127_119402953f0da2fdf8d99efb649c8cf0.png

입력 2

2 3 6
1 1
1 2
1 3
2 1
2 2
2 3

출력 2

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.