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$ の正方形マスからなる格子と考えると、各干し草の束はちょうど 1 マスを占めます(もちろん、2 つの束が同じマスを占めることはありません)。

FJ はすべての干し草の束が 1 つの大きな連結領域を作っていることに気づきました。つまり、どの束から出発しても、北、南、東、西に直接隣り合う束へ順に移動して、ほかのどの束にも到達できます。ただし、この連結領域には「穴」、すなわち干し草の束に完全に囲まれた空の領域が含まれる場合があります。

干し草の束が作る領域の周長を FJ が求めるのを手伝ってください。穴は周長に含めないことに注意してください。

入力

  • 1 行目:干し草の束の数 $N$。

  • 続く $N$ 行、すなわち $2\ldots1+N$ 行目:各行には 1 つの束の位置($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.