#C3513. Unique Prefix Character Check
Unique Prefix Character Check
Unique Prefix Character Check
You are given a string s consisting of lowercase English letters and a list of integers p of length equal to the length of s. The list p specifies the required number of unique characters for each prefix of s. In other words, for every i from 1 to |s|, the substring s[0:i]
must contain exactly p[i-1] distinct characters.
Your task is to determine whether the string s satisfies these conditions. Formally, let \( s = s_1 s_2 \cdots s_n \) and let \( p = [p_1, p_2, \dots, p_n] \). The condition that must be met is:
[ \forall, 1 \le i \le n,\quad |{ s_1, s_2, \dots, s_i }| = p_i ]
If the condition holds for all prefixes, print True
. Otherwise, print False
.
inputFormat
The input is given on standard input and consists of two lines:
- The first line contains the string s.
- The second line contains \( n \) space-separated integers which represent the list p (where \( n \) is the length of s). In the case that s is empty, the second line will also be empty.
outputFormat
Print a single line True
if for every prefix of s the number of unique characters equals the corresponding value in p, and False
otherwise.
abac
1 2 2 3
True