#CT0000067. Tần suất độ dài theo ngưỡng (Word Length Frequencies Above a Threshold)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Tần suất độ dài theo ngưỡng (Word Length Frequencies Above a Threshold)
Word Length Frequencies Above a Threshold
Problem Statement
A word is a nonempty consecutive sequence of English letters (A–Z, a–z) or digits (0–9). Exactly one ASCII space separates consecutive words. There are no leading or trailing spaces.
You are given a positive integer and a string . For each word length , let be the number of words in whose length is exactly .
Output every length satisfying , together with , sorted by increasing .
Input
- The first line contains a positive integer .
- The second line contains a string with at least one word.
Output
- Print , the number of distinct lengths meeting the threshold.
- On the next lines, print and in increasing order of . If , print no further lines.
Subtasks
-
The string contains only English letters, digits and ASCII spaces; .
-
Subtask 1 (30%): and .
-
Subtask 2 (30%): .
-
Subtask 3 (40%): .
Examples
Example 1
Input
2
Ky thi HSG THCS 2026
Output
2
3 2
4 2
Explanation
The five words have lengths , so , , and . With , exactly two lengths qualify: and . Print 2, followed by 3 2 and 4 2 in increasing length order.
Example 2
Input
3
a bb cc dd e f
Output
2
1 3
2 3
Explanation
The lengths of a, bb, cc, dd, e, and f are . Hence and . Both meet , so print the number of qualifying lengths, 2, then 1 3 and 2 3.
Example 3
Input
4
aa b ccc dd
Output
0
Explanation
The words have lengths . Length occurs twice; all others occur once. No length occurs at least times, so the only output is 0.