Problems 25 - Codeforces
Problems 25 - Codeforces
Contest 26 (Icathia)
A. Beautiful Strings
1 second, 256 megabytes
You are given an integer n. Determine the number of strings of length 𝑛 which are beautiful modulo 109 + 7.
A string is called beautiful if it is lexicographically (alphabetically) sorted and only consists of vowels [𝑎𝑒𝑖𝑜𝑢].
The strings 𝑎𝑒𝑖𝑜𝑢 and 𝑎𝑎𝑜𝑢 are beautiful strings as they are lexicographically sorted and consist of vowels only but string 𝑎𝑧 is not beautiful as it
consists of the non-vowel alphabet and string 𝑒𝑎 is not beautiful as it is not lexicographically sorted.
Constraints
1 ≤ 𝑇 ≤ 102
1 ≤ 𝑛 ≤ 106
Input
The first line contains an integer 𝑇 denoting the number of test cases.
For each test case:
The first line contains a single integer 𝑛 denoting the length of the string.
Output
For each test case in a new line, print the answer.
input
input
2
1
2
output
output
5
15
B. Alphabetical String
1 second, 256 megabytes
While creating an account on a new website, you choose a certain string of letters as your password. However, you are alerted that the website
requires your password to be an alphabetical string. It explains, "A string of lowercase letters is called alphabetical if deleting zero or more of its letters
can result in the alphabet string abcdefghijklmnopqrstuvwxyz."
Because of this requirement, you need to ensure that your password is alphabetical. Your goal is to find the minimum number of letters that must be
inserted in order to make your password alphabetical.
Example: Given string 𝑠 = "xyzabcdefghijklmnopqrstuvw", the optimal solution is to insert "xyz" at the end of the string to obtain the alphabetical
string "xyzabcdefghijklmnopqrstuvwxyz". (Note that this is alphabetical because if you delete the first three letters, "xyz", it results in the alphabet
string "abcdefghijklmnopqrstuvwxyz".) Because this requires 3 letter insertions, the answer is 3. There is no way to make fewer than 3 insertions and
end up with an alphabetical string.
Constraints
1 ≤ 𝑇 ≤ 30
1 ≤ Length of string s ≤ 105
𝑠 contains only lowercase english letters
Input
Each of the next 𝑇 lines contains a string 𝑠 denoting the string that you are required to make alphabetical.
https://codeforces.com/gym/531207/problems Page 1 of 2
Problems - Codeforces 21/06/24, 11:07 AM
Each of the next 𝑇 lines contains a string 𝑠 denoting the string that you are required to make alphabetical.
Output
For each test case, print the minimum number of letters that must be inserted in order to make your password alphabetical, in a new line.
input
input
1
zgwabcdegqwdhiklmnopqadsrtuwevxzgwe
output
output
5
In this sample, one optimal way to do the task is to insert 'f', 'j', 's', 'w', and 'y' to obtain the alphabetical string.
"zgwabcdefgqwdhijklmnopqadsrstuwevwxyzgwe", which contains all the english letters in alphabetical order (as seen in bold). Since there is no way
to do this with fewer than 5 insertions, the answer is 5.
You are given a number 𝑛 . Find the decimal value of the number that is formed by concatenating the binary representation of the first 𝑛 positive
9
integers. Print the answer modulo 10 + 7 .
Example: Consider 𝑛 = 2.
Constraints
1 ≤ 𝑛 ≤ 109
Input
The first line contains an integer 𝑛 .
Output
9
Print the answer modulo 10 + 7.
input
input
3
output
output
27
Binary representation of 1: 1
Binary representation of 2: 10
Binary representation of 3: 11
https://codeforces.com/gym/531207/problems Page 2 of 2