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

30491번 - Compressing Commands 다국어

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

문제

Unlike your friends, you live in a terminal. You are cool. Your terminal is everything to you: you have optimized the font, colour scheme, keyboard shortcuts, and what not.

Once thing still annoys you though: all these commands you're typing involve so many file paths and are so long! Then it occurs to you: all this time you have been working from the root directory of the file system, but in fact you can change directory to anywhere you like! This should simplify your life a lot!

This way, if your working directory is /a/b, you can refer to the absolute file path /a/b/x using simply x. To go up a level, you can use .., so that you can refer to /a/y/z as ../y/z, and to /some/other/directory as ../../some/other/directory.

You being you, of course you overdo this and will now use relative paths everywhere!

Given the $n$ absolute file paths in the command you want to run, find the working directory that minimizes the total number of relative path components. For example, a/a/b/c, and ../../a/b both contain 4ドル$ path components. Note that you can only change the working directory to a directory and not to a file path. Filenames will never coincide with directory names in the same directory.

In the first sample it is best to set the working directory to /home/jury/compressingcommands, leading to 6ドル$ components: secret, solutions, and ../../hackerman/answers.

In the second sample it is best to set the working directory to /a, leading to 19ドル$ path components: b/a/a/b, a/a, ../b, a/b, b/a/a/a, ../c, and b/a/b.

입력

The input consists of:

  • One line with an integer $n$ (1ドル\leq n\leq 10^5$), the number of absolute file paths.
  • $n$ lines, each with a string $s,ドル an absolute file path. Each path contains only lowercase English letters (a-z) and slashes ('/'), starts with '/', does not end with '/', and does not contain consecutive slashes ("//").

The total number of characters in the $n$ strings is at most 10ドル^6$.

출력

Output the minimal number of relative path components that can be achieved by changing to a different working directory.

제한

예제 입력 1

3
/home/jury/compressingcommands/secret
/home/jury/compressingcommands/solutions
/home/hackerman/answers

예제 출력 1

6

예제 입력 2

7
/a/b/a/a/b
/a/a/a
/b
/a/a/b
/a/b/a/a/a
/c
/a/b/a/b

예제 출력 2

19

예제 입력 3

3
/x/y/z
/x/y/z
/x/y/z

예제 출력 3

3

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2023 C번

  • 문제를 만든 사람: Ragnar Groot Koerkamp
(追記) (追記ここまで)

출처

대학교 대회

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

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