#P3989. Factorial String Checker
Factorial String Checker
Factorial String Checker
Given a string \(S\) composed only of the first \(n\) lowercase letters (i.e. the letters \(a, b, \ldots, \text{chr}(\text{ord}(a)+n-1)\)) – note that \(S\) may contain duplicate letters – we say that \(S\) is a factorial string if and only if every permutation of these \(n\) letters appears as a subsequence (not necessarily contiguous) of \(S\).
Your task is to determine, within 1 second, whether the given string \(S\) is a factorial string.
Definitions:
- Let \(n\) be determined by the maximum letter in \(S\). In particular, if the maximum character in \(S\) is \(\mathtt{chr}(\text{ord}(a)+n-1)\), then the allowed set is \(\{a, b, \ldots, \mathtt{chr}(\text{ord}(a)+n-1)\}\). It is assumed that \(S\) contains exactly these \(n\) distinct letters (possibly with repetitions).
- A subsequence of \(S\) is a sequence obtained by deleting zero or more characters from \(S\) (without changing the order of the remaining characters).
Input Constraints: \(S\) is non-empty and is guaranteed to contain only the first \(n\) lowercase letters for some \(n \ge 1\).
inputFormat
The input consists of a single line containing the string \(S\).
outputFormat
Output a single line containing YES
if \(S\) is a factorial string, or NO
otherwise.
sample
abcacbacb
YES