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

11629번 - The King’s Walk 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 256 MB117332640.625%

문제

Chess is a game in which two sides control pieces in an attempt to capture each other’s king. The pieces vary in mobility. At the beginning of a game the kings are rather vulnerable. They are less mobile than most other pieces and they tend to hide behind their pawns. Like in real life, as soon as both queens have left the game it is time for the kings to come into action. Because there is little threat left for the king, he can now move safely around the board. Indeed his mobility seems to be quite strong at this stage making him one of the more dangerous pieces. Your task is to measure the mobility of the king in the endgame.

Consider a chess board of N × N squares. The king is the only piece on the board. He starts at a given position and wants to go to another given position in the minimum number of moves. The king can move to any adjacent square in any orthogonal or diagonal direction.

입력

The input starts with a line containing an integer T, the number of test cases. Then for each test case:

  • One line with a single integer N, the size of the board, where 2 ≤ N ≤ 5,000.
  • One line with four space-separated integers X1, Y1, X2, Y2, such that 1 ≤ X1, Y1, X2, Y2 ≤ N, where (X1, Y1) is the square on which the king starts and (X2, Y2) is the square the king wants to go to (different from his starting position).

출력

For each test case, output one line with a single integer: the number of ways by which the king can reach the destination square in the minimum number of moves. As this number can be very large, you must reduce your answer modulo 5,318,008.

제한

예제 입력 1

2
3
1 2 3 2
8
2 2 7 7

예제 출력 1

3
1

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2015 E번

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

출처

대학교 대회

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

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