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

9710번 - Rooks 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB69302445.283%

문제

You have a chessboard with N rows and N columns. Initially you have N rooks placed in various squares of the chessboard. Two rooks attack each other if they are on the same cell or in the same column or in the same row. In each step you can move a rook one cell up/down/left/right. You cannot move it diagonally. You have to move these N rooks into N different squares with minimum steps so that none of them attack each other.

입력

The first line of the input gives an integer T, which is the number of test cases. Each test case starts with N. Each of the next line contains 2 integers (between 1 and N inclusive) in each line denoting the row and column of the rook. N can be as big as 20000.

출력

For each test case, the output contains a line in the format Case #x: M, where x is the case number (starting from 1) and M is the minimum number of steps needed to move the rooks.

제한

예제 입력 1

2
3
1 1
1 1
1 1
4
1 1
1 1
1 3
3 1

예제 출력 1

Case #1: 6
Case #2: 8

힌트

출처

ICPC > Regionals > Asia Pacific > Malaysia > Malaysia National Programming Contest > Al-Khawarizmi National Programming Contest 2012 H번

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

출처

대학교 대회

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

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