#P12814. [NERC 2021] Admissible Map
[NERC 2021] Admissible Map
题目描述
A is a matrix consisting of symbols from the set of , , , and .
A of a map matrix is a directed graph with vertices numbered as (), where is the number of rows in the matrix, is the number of columns in the matrix. The graph has directed edges , where ; ; ; . A map graph is when all edges point to valid vertices in the graph.
An is a map such that its map graph is valid and consists of a set of cycles.
A of a map is a concatenation of all rows of the map --- a string $a_{1,1} a_{1,2} \ldots a_{1, m} a_{2, 1} \ldots a_{n, m}$.
You are given a string . Your task is to find how many substrings of this string can constitute a description of some admissible map.
A of a string of length is defined by a pair of indices and () and is equal to . Two substrings of are considered different when the pair of their indices differs, even if they represent the same resulting string.
输入格式
In the only input line, there is a string , consisting of at least one and at most symbols , , , or .
输出格式
Output one integer --- the number of substrings of that constitute a description of some admissible map.
RDUL
2
RDRU
0
RLRLRL
6
提示
In the first example, there are two substrings that can constitute a description of an admissible map --- as a matrix of size (pic. 1) and as a matrix of size (pic. 2).
In the second example, no substring can constitute a description of an admissible map. E.g. if we try to look at the string as a matrix of size , we can find out that the resulting graph is not a set of cycles (pic. 3).
In the third example, three substrings , two substrings and one substring can constitute an admissible map, some of them in multiple ways. E.g. here are two illustrations of substring as matrices of size (pic. 4) and (pic. 5).