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

30908번 - Klompendans 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB115907484.091%

문제

In traditional Dutch clog dancing, you as the dancer need to follow a very specific sequence of movements. The dance takes place on a square grid of square tiles, and at the start of the dance you stand on the top left corner tile of the grid. You then alternate between two types of dance move, moving from tile to tile in the grid for as long as you want. Your first move may be of either kind, but after that you need to strictly alternate between the two kinds of moves.

Both moves are similar to knight moves in chess: in the first type of move, you go from your current square to a square that is $a$ tiles away along one axis of the grid and $b$ tiles away along the other axis. Similarly, in the second type of move, you need to move $c$ and $d$ tiles along the respective axes. As you can freely swap the two axes and choose the movement direction along each axis, there can be up to 8ドル$ ways of performing a given type of move. Figure K.1 shows an example dance routine with $(a,b) = (1,2)$ and $(c,d) = (2,3)$.

Figure K.1: Illustration of Sample Input 3, showing a dance that begins in the top left corner of a 4ドル\times 4$ grid and ends in the bottom left corner, visiting the blue squares along the way. There are 13ドル$ reachable squares in total. The three squares highlighted in red cannot be part of any dance performance.

Starting on the top left corner tile, how many different tiles could you reach while doing a clog dance? It is not allowed to step outside of the grid and you do not count tiles that you are simply stepping over while doing a move. Note that you need to count all tiles that can be reached during some performance of the dance, but not necessarily during the same one.

입력

The input consists of:

  • One line with an integer $n$ (3ドル\leq n\leq 500$), the side length of the square.
  • One line with two integers $a$ and $b$ (1ドル\leq a, b < n$), describing the first dance move.
  • One line with two integers $c$ and $d$ (1ドル\leq c, d < n$), describing the second dance move.

출력

Output the number of tiles you can reach using these dance moves.

제한

예제 입력 1

8
1 2
1 2

예제 출력 1

64

예제 입력 2

4
1 2
2 3

예제 출력 2

13

예제 입력 3

5
1 2
2 3

예제 출력 3

25

예제 입력 4

10
3 3
4 4

예제 출력 4

50

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2023 K번

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

출처

대학교 대회

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

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