Aligned Typesetting
InterviewTime limit2sMemory limit512 MB
Given an equal number of spaces between every pair of consecutive words, decide whether one such aligned typesetting has total length exactly L.
- Level
Easy3 of 10
- Topics
- String, Math, Implementation
- Solved
- No attempts yet
Problem
In this problem, a sentence with words is a sequence of non-empty strings . Given a sentence, a valid typesetting of length is a string of length exactly formed by concatenating all the words in the sentence in order and inserting a positive number of spaces between each adjacent pair of words.
An aligned typesetting is a valid typesetting in which the number of spaces between each adjacent pair of words is the same.
For example, given the sentence and using _ to indicate a space:
- the string
__harry_ronhermioneis not a valid typesetting; - the string
harry_ron_____hermioneis a valid typesetting of length 22, but it is not an aligned typesetting; - the string
harry___ron___hermioneis an aligned typesetting of length 22.
Darcy was given a sentence of words and the desired length of typesetting . Can you help him figure out whether an aligned typesetting of the desired length exists?
Input
The first line contains two integers (), the number of words, and (), the desired length of typesetting.
The next lines describe the words. Each of these lines contains a single string , the -th word in the sentence. The word contains only lowercase letters and has length between 1 and .
The total length of all the words in the sentence is at most .
Output
Display whether the sentence has an aligned typesetting of the given length .