RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00607

Ekoeko

Unrated 레이팅 미적용
난이도
1s
시간 제한
512MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

You must be familiar with the story of an alien called Eko Eko, who got his name
due to a malfunction in his translation device. The little alien is once again back
on Earth to help earthlings with a cle\(an-up\) after the Advent. However, Eko Eko’s
translation device has stopped working again.
This time, not only does the device repeat a word, but it also changes the order
of the letters in a word. For example, the word “slon” first becomes “slonslon”,
and then by changing the order of the letters it could become “slosnoln” or
“soolnlsn” etc. The amount of gold needed to repair Eoo Kek’s device depends
on the number of swaps of adjacent characters needed to make Kok Oee’s badly
translated word into a word which is made from just repetition.
For example, if Keo Koe’s device translates a word to “soolnlsn“, it is sufficient to make four swaps of
adjacent characters to obtain a word which is made from a repetition - “olsnolsn“ (see the clarification of
the third example), so four pieces of gold are enough to repair his device. Notice that the word obtained
from a sequence of such swaps is not necessarily the word that Koo Kee originally wanted to say. This
does not effect the amount of gold needed to repair his device.
You would like to help Eke Koo, but if you steal a large amount of jewelry from your mother you won’t
get a Christmas present. That’s why for a given word that came out of Keo Koe’s translation device, you
want to determine the least possible number of swaps of adjacent characters to get a word which is made
from just repetition.

제약

Subtask 1 (10 points): The string consists of \(n\) occurrences of a, and then \(n\) of b.

Subtask 2 (20 points): Each letter appears at most twice.

Subtask 3 (20 points): The first \(n\) and the last \(n\) letters are the same, but possibly in a different order.

Subtask 4 (20 points): \(1 \le n \le 1000\)

Subtask 5 (40 points): No additional constraints.

입력 형식

The first line contains a positive integer \(n - th\)e length of the word that Eek Ook is trying to say.
The second line contains a sequence of 2\(n\) characters, each being a lowercase letter of the Latin alphabet,
representing the word that came out of Eok Eok’s translation device. Each letter will appear an even
number of times.

출력 형식

In the only line print the least possible number of swaps of adjacent characters to make Keo Koe’s word
into a sing\(le-re\)petition word.

서브태스크
서브태스크점수설명

1

10점

The string consists of \(n\) occurrences of a, and then \(n\) of b.

2

20점

Each letter appears at most twice.

3

20점

The first \(n\) and the last \(n\) letters are the same, but possibly in a different order.

4

20점

\(1 \le n \le 1000\)

5

40점

No additional constraints.

예제 1
입력
3
koeeok
출력
3
예제 2
입력
3
kekoeo
출력
1
예제 3
입력
4
soolnlsn
출력
4
설명

Clarification of the third example:
One way to get from soolnlsn to a single-repetition word using four swaps is
soolnlsn →solonlsn →solnolsn →oslnolsn →olsnolsn

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2021/2022 Contest 3

평가 및 의견

Ekoeko

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Ekoeko

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8