No.2590 100000 Days of Christmas
Problem Statement
For $N$ days starting from Christmas of $2023$, magurofly gives presents to p-shin Daisuki bot every day. The presents given on day $i$ are $i$ copies of $S_i$ and, when $i \ge 2$, additionally all of the presents given on day $i-1$.
Find how many of each present p-shin Daisuki bot receives in the end.
Input
$N\\S_1\\S_2\\\vdots\\S_N$
- $N$ is an integer.
- $1 \le N \le 10^5$
- $S_i$ is a string consisting of characters whose ASCII codes are between
0x20and0x7e, inclusive. - The last character of $S_i$ is not a space.
- $1 \le |S_i| \le 100$
- $\sum_i |S_i| \le 10^6$
If you use C++, note that reading a string with cin >> stops at a space.
Output
If $K$ kinds of presents are given in total, print $K$ lines.
When the names of the presents are arranged in lexicographical (ascending) order, let $P_k$ be the $k$-th name. Also, let $C_k$ be the number of $P_k$ received as presents.
What is lexicographical order?
For strings $s, t$, the lexicographical order between them can be determined as follows.
- If there exists a minimum $i \in [1, \min\{|s|, |t|\}]$ such that $s_i \ne t_i$ in terms of ASCII codes, the order between $s$ and $t$ is the same as the order between $s_i$ and $t_i$.
- If no such $i$ exists, the order is the same as the order between $|s|$ and $|t|$.
Note that many major programming languages provide functions for sorting strings in lexicographical order. See the reference for each language for details.
For $k = 1, 2, \ldots, K$, print $C_k$ and $P_k$ separated by a space on the $k$-th line.
Sample
Sample 1
Input
7 Div. 2 ECR Petrozavodsk Contest Div. 2 yukicoder ABC joyacon
Output
12 ABC 23 Div. 2 12 ECR 15 Petrozavodsk Contest 7 joyacon 15 yukicoder
The presents received on each day are as follows:
Div. 2×1Div. 2×1,ECR×2Div. 2×1,ECR×2,Petrozavodsk Contest×3Div. 2×5,ECR×2,Petrozavodsk Contest×3Div. 2×5,ECR×2,Petrozavodsk Contest×3,yukicoder×5ABC×6,Div. 2×5,ECR×2,Petrozavodsk Contest×3,yukicoder×5ABC×6,Div. 2×5,ECR×2,Petrozavodsk Contest×3,joyacon×7,yukicoder×5
Sample 2
Input
12 partridge in a pear tree turtle dove french hen calling bird golden ring goose a-laying swan a-swimming maid a-milking lady dancing lord a-leaping piper piping drummer drumming
Output
36 calling bird 12 drummer drumming 30 french hen 40 golden ring 42 goose a-laying 36 lady dancing 30 lord a-leaping 40 maid a-milking 12 partridge in a pear tree 22 piper piping 42 swan a-swimming 22 turtle dove
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。