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

G. Glossary Arrangement

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

In Unix based operating systems, one of the most frequently used commands is ls, which displays a list of all the files in a directory in lexicographic order. In the most basic form, ls prints each filename on a separate line, but to improve readability and save screen space, the list is usually split into multiple columns which are displayed side by side.

A friend of yours is writing a book about NWERC and has put you in charge of editing the glossary of relevant terms at the end of each chapter. Each glossary must use the same multi-column layout as ls, so you decided to go for the lazy option: For each word in the glossary, you created an empty file with that name, and simply let ls do the heavy lifting.

Unfortunately, your friend is not satisfied with your layouts and complains that some of them take up too much vertical space. The problem with your approach is that ls always forms columns of equal height, except for the last column, which may be shorter. This sometimes ends up using more lines than would be needed if the column heights could be chosen more freely:

Begrudgingly, you decide to write your own improved version of ls, ls--, that also displays the contents of a directory in lexicographic order, but uses variable column heights to always achieve the lowest possible number of lines.

Columns have a fixed width, which is the length of the longest filename within the column, and are separated by a single space. The names in each column must be left-aligned and padded to the column width using spaces. Also, the terminal you are using has a fixed width of \(w\) characters which the table may not exceed.

Given the contents of a directory as a list of filenames, find an optimal column layout that minimizes the number of lines needed to print the entire list.

제약
입력 형식

The input consists of:
- One line with two integers \(n\) and \(w\) (\(1 \le n,w \le 5\,000\)), the number of files and the width of the terminal.
- \(n\) lines, each with one filename \(s\) (\(1 \le |s| \le w\), \(s\) consists of lowercase English letters).

The filenames are distinct and in lexicographic order. The total number of letters is at most \(10^6\).

출력 형식

Output an optimal way of listing the given filenames:
- One line with two integers \(r\) and \(c\), the number of lines and the number of columns used.
- One line with \(c\) positive integers \(a_1, a_2, \ldots, a_c\), the widths of the columns.
- The table of filenames, subject to the following formatting:
- There are \(c\) columns, where column \(i\) has width \(a_i\) for each \(i\), and within each column there are at most \(r\) filenames that are aligned on the left and grouped at the top.
- The filenames are aligned using spaces, with exactly one space between columns.
- The total width of the table is at most \(w\).
- When reading column by column, the filenames appear in lexicographic order.

Note that unlike in other problems, you strictly need to follow the above formatting rules for whitespace. However, we still allow trailing whitespace at the end of each line, even if this whitespace exceeds the width \(w\).

예제 1
입력
9 30
algorithm
contest
eindhoven
icpc
nwerc
programming
regional
reykjavik
ru
출력
3 4
9 5 11 2 
algorithm icpc  programming ru
contest   nwerc regional      
eindhoven       reykjavik     
예제 2
입력
6 10
aaa
bb
ccccc
ddd
eeeee
fffff
출력
4 2
3 5
aaa ccccc
bb  ddd
    eeeee
    fffff
예제 3
입력
5 15
pppp
ppppp
pq
pqab
xyzff
출력
2 3
5 2 5
pppp  pq pqab
ppppp    xyzff
문제 정보

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

출처 ICPC NWERC 2021

평가 및 의견

G. Glossary Arrangement

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

Log in to rate problems.

개별 의견

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

풀이 제출

G. Glossary Arrangement

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