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

32589번 - Flag Rotation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB30252080.000%

문제

A common pattern for country flags is three stripes. Some flags are really similar, and have exactly the same stripes in the same order, but the flag is rotated by 90ドル$ degrees. Using a sequence of colours, we can make a flag on a square grid, covering each row with the colours in the sequence. Another way to make a similar flag (that is rotated by 90ドル$ degrees), is by covering each column with the colours in the sequence.

In preparation for the Flags You Paint for Countries meeting, you notice a mistake for one of the flags: it should have been rotated counter-clockwise by 90ドル$ degrees! The square canvas is already stuck to a wall using super glue, so you can not simply take it off and rotate it. Therefore, you want to know how much work it would be to repaint one flag to the other. In one second, you can repaint one of the 1ドル \times 1$ squares to any colour. What is the minimum number of seconds you need to repaint the flag? As an example, for the flag in the first sample input (shown in Figure F.1), 34ドル$ squares need to be repainted.

Figure F.1: Two flags corresponding to the first sample input. Colour 1ドル$ corresponds to yellow, 2ドル$ to red, 3ドル$ to white, and 1000ドル$ to blue. When the first flag should be rotated counter-clockwise by 90ドル$ degrees without actually rotating the canvas, 34ドル$ squares need to be repainted.

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 2 \cdot 10^5$), the number of stripes in the flag.
  • One line with $n$ integers $a$ (1ドル\leq a\leq 10^9$), the colours of the stripes.

출력

Output the number of cells that need to be repainted when the flag should be rotated counter-clockwise by 90ドル$ degrees.

제한

예제 입력 1

7
1 2 2 3 1000 2 1

예제 출력 1

34

예제 입력 2

4
10 12 12 10

예제 출력 2

8

예제 입력 3

5
6 5 5 6 5

예제 출력 3

12

힌트

출처

University > Delft University of Technology > Freshmen Programming Contest 2024 F번

  • 문제를 만든 사람: Jeroen Op de Beek
(追記) (追記ここまで)

출처

대학교 대회

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

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