포럼
문제 ICPC00348

C. Compressing Commands

설명

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
출력
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
출력
19
예제 3
입력
3
/x/y/z
/x/y/z
/x/y/z
출력
3
문제 정보

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

출처 ICPC BAPC 2023

평가 및 의견

C. Compressing Commands

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

Log in to rate problems.

개별 의견

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

풀이 제출

C. Compressing Commands

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