No.3110 Like CPCTF?
問題文最終更新日: 2025-04-18 22:19:58
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
CPCTF 2025 : PPC
(順位表)
の他の問題:
Problem Statement
A string $S$ consisting of uppercase English letters is said to be CPCTF-like if the length of $S$ is 5 and $S_i = S_j$ is equivalent to $i = j \vee \lbrace i,j \rbrace = \lbrace 1,3\rbrace$. (Here, $S_i$ denotes the $i$-th character of $S$.)
In other words, it is a string of length 5 consisting only of uppercase English letters in which only the $1$-st and $3$-rd characters are equal and every other character appears only once in $S$. For example, $\mathrm{ABACD}$ is CPCTF-like, but $\mathrm{ABABC}$ is not. You are given a string $S$ of length $N$ consisting of uppercase English letters. How many not necessarily contiguous substrings of $S$ are CPCTF-like? Here, substrings taken from different positions are counted as different even if they are the same as strings.Constraints
- $1 \leq N \leq 30$
- $S$ is a string of length $N$ consisting only of uppercase English letters
Input
The input is given from standard input in the following format.
$N$ $S$
Output
Output, in one line, the number of CPCTF-like not necessarily contiguous substrings.
Sample
Sample 1
Input
11 NEOSHOWCASE
Output
16
The string $\mathrm{NEOSHOWCASE}$ contains the string $\mathrm{OSOCE}$ as a substring, and this is a CPCTF-like string.
The CPCTF-like substrings contained in this string are the 16 whose $1$-st and $3$-rd characters are $\mathrm{O}$.
Sample 2
Input
3 PPC
Output
0
Sample 3
Input
30 CPCTFCPCTFCPCTFCPCTFCPCTFCPCTF
Output
4011
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。