Logo
(追記) (追記ここまで)

23506번 - Coins 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 128 MB43343076.923%

문제

You are given an $N\times N$ matrix and in exactly $N$ of its cells there is a single coin. You are going to play a game on this matrix where in one turn you can take a coin and move it to any adjacent cell. Two cells are adjacent if they share a side. However, during these moves, no two coins may occupy the same cell at the same time. Your goal is to make every row and column contain exactly one coin in as few moves as possible. Determine the minimum number of moves required.

입력

In the first line of input is the number $N$ ($N\leq 200000$): the number of rows, columns and coins.

In the $(i+1)$-th line are two integers $r_i$ and $c_i,ドル denoting the initial row and column of the $i$-th coin. It is guaranteed that all pairs $(r_i,c_i)$ are different.

출력

Print a single integer: the minimum number of moves required to win at the game.

제한

예제 입력 1

3
2 1
2 2
2 3

예제 출력 1

2

힌트

출처

Contest > Open Cup > 2019/2020 Season > Stage 19: The Grand Prix of Serbia H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /