QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21336. 둘레

Statistics

Farmer John은 자신의 밭 하나의 중앙에 건초 더미 $N$개($(1 \le N \le 50,000)$)를 놓았습니다. 밭을 $1,000,000$ $x$ $1,000,000$개의 $1$ $x$ $1$ 정사각형 칸으로 이루어진 격자로 생각하면, 각 건초 더미는 정확히 한 칸을 차지합니다(물론 두 더미가 같은 칸을 차지하지는 않습니다).

FJ는 모든 건초 더미가 하나의 큰 연결 영역을 이룬다는 것을 알아챘습니다. 즉, 어느 더미에서 시작하든 북쪽, 남쪽, 동쪽 또는 서쪽으로 바로 인접한 더미로 차례로 이동하면 다른 어느 더미에도 도달할 수 있습니다. 하지만 이 연결 영역에는 건초 더미로 완전히 둘러싸인 빈 영역인 “구멍”이 있을 수 있습니다.

건초 더미가 이루는 영역의 둘레를 구하도록 FJ를 도와주세요. 구멍은 둘레에 포함되지 않습니다.

입력

  • 1번째 줄: 건초 더미 수 $N$.

  • 다음 $N$개 줄, 즉 $2\ldots1+N$번째 줄: 각 줄에 건초 더미 하나의 위치 ($x$, $y$)가 주어지고, $x$와 $y$는 모두 $1\ldots1,000,000$ 범위의 정수입니다. 위치 $(1,1)$은 밭의 왼쪽 아래 칸이고, $(1000000,1000000)$은 오른쪽 위 칸입니다.

출력

  • 1번째 줄: 건초 더미의 연결 영역의 둘레.

예제

입력 1

8
10005 200003
10005 200004
10008 200004
10005 200005
10006 200003
10007 200003
10007 200004
10006 200005

출력 1

14

참고

건초 더미로 이루어진 연결 영역은 다음과 같습니다.

XX 
X XX
XXX

연결 영역의 둘레 길이는 $14$입니다(예를 들어 왼쪽 변은 전체 길이에 $3$만큼 기여합니다). 가운데 구멍은 이 값에 포함되지 않습니다.

문제 제작: Brian Dean, 2013

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.