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

17194번 - Balancing Inversions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB157635741.606%

문제

Bessie and Elsie were playing a game on a boolean array $A$ of length 2ドルN$ (1ドル \leq N \leq 10^5$). Bessie's score was the number of inversions in the first half of $A,ドル and Elsie's score was the number of inversions in the second half of $A$. An inversion is a pair of entries $A[i]=1$ and $A[j]=0$ where $i<j$. For example, an array consisting of a block of 0s followed by a block of 1s has no inversions, and an array consisting of a block of $X$ 1s follows by a block of $Y$ 0s has $XY$ inversions.

Farmer John has stumbled upon the game board and is curious to know the minimum number of swaps between adjacent elements needed so that the game looks like it was a tie. Please help out Farmer John figure out the answer to this question.

입력

The first line of input contains $N,ドル and the next line contains 2ドルN$ integers that are either zero or one.

출력

Please write the number of adjacent swaps needed to make the game tied.

제한

예제 입력 1

5
0 0 0 1 0 1 0 0 0 1

예제 출력 1

1

힌트

In this example, the first half of the array initially has 1ドル$ inversion, and the second half has 3ドル$ inversions. After swapping the 5ドル$th and 6ドル$th bits with each other, both subarrays have 0ドル$ inversions.

출처

Olympiad > USA Computing Olympiad > 2018-2019 Season > USACO 2019 US Open Contest > Gold 3번

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

출처

대학교 대회

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

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