Codeforces 1166B. All the Vowels Please Codeforces Round #561 (Div. 2)


Problem link

First, which boards could we feasibly fill with characters satisfying that every row and column contains one vowel at least once? Well, if we have a board with less than 5 rows, then each column contains less than 5 characters, so we cannot have every vowel on each column, and we can't fill the board. Similarly, we can't fill a board with less than 5 columns.

Ok, so say now that we have a board with at least 5 rows and at least 5 columns. Can we fill it? Yes we can! It's enough to fill it by diagonals.
Now we can easily solve the problem. If n⋅m=k, then n must divide k and m=k / n. So we can iterate over all possible n from 5 to k, check whether n divides k and in that case, check whether m=k / n is at least 5. If this works for at least one value of n then we can fill the n⋅m board by diagonals as shown before, and obtain our vowelly word by reading the characters row by row. If we don't find any values of n satisfying this, then no vowelly word exists.

Complexity: O(k).


A solution in c++



Post a Comment

0 Comments