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

17564번 - Dishonest Driver 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
6 초 512 MB88534361.429%

문제

When you arrived at Charles de Gaulle airport, you naively accepted a ride to Paris by an unauthorized driver who offered you “competitive prices”. The end result was a disaster: not only was the price extremely high, but the driver made the trip much longer than necessary in order to justify that price.

You noticed the scam because you were traveling several times by the same place: indeed, you have such a good memory that you can remember very well the path you followed, including each of the loops that your scammer forced you to take.

Now, you are at the police station to fill a complaint against this driver and an officer asks you to tell your story. She even asks you to give all the details of the path you took. Because you do not want to lose yet another couple of hours in doing so, you decide to give a compressed version of it.

Suppose you remember you traveled through places A, B, C, D, A, B, C, D. In this case, you prefer telling the officer “I followed twice the path ABCD”, rather than “I followed the path ABCDABCD”. Given that your path repeated the same sequence of places, this will significantly shorten your statement, without missing any detail.

More precisely, you have to write a program that takes as input the list of places you traveled through, and which returns the size of the shortest compressed form of this path. Such a compressed path can either be:

  • a single place through which you traveled, called an “atomic path”;
  • the concatenation of two compressed paths;
  • the repetition of a compressed path, i.e., (C)n, meaning that you traveled through the path described by C, n times in a row.

The size of a compressed path is defined as the number of atomic paths it contains.

입력

The input consists of two lines:

  • The first line contains one integer, N, the length of the path.
  • The second line contains the path, described as a string of size N. Each location is described by an alphanumeric character: either a digit (from ‘0’ to ‘9’), a lowercase letter (from ‘a’ to ‘z’) or an uppercase letter (from ‘A’ to ‘Z’).

출력

The output should consist of a single line, whose content is an integer, the size of the shortest compressed path.

제한

  • 0 < N ≤ 700

예제 입력 1

22
aaabaaabccdaaabaaabccd

예제 출력 1

4

The shortest compressed form of the path is (((a)3b)2(c)2d)2. The atomic paths it contains are a, b, c and d. Hence, it has size 4.

예제 입력 2

4
aaba

예제 출력 2

3

The shortest compressed form of the path is (a)2ba. The atomic paths it contains are a, b, and a. Hence, it has size 3.

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2018 K번

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

출처

대학교 대회

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

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