#P5270. 无论怎样神树大人都会删库跑路
无论怎样神树大人都会删库跑路
Description
There is a string of length and small strings .
You are given an array of length , indexed starting from 1. Initially, there is an empty string . Lord Divine Tree will perform operations. In the -th operation, he appends the small string to the end of .
After each operation, Lord Divine Tree checks whether the string has a suffix such that, after an arbitrary permutation, it can become .
Ask how many times the string has a suffix that can become after an arbitrary permutation (that is, the counts of all characters are the same).
Unfortunately, the character set size of this string is as large as , so you must read the strings as integer arrays.
Input Format
Input .
Then input numbers representing the string .
Then input lines. In each line, the first number is the length, followed by numbers representing this small string. Each input number is in the range .
Then input .
Input one line with numbers representing .
Output Format
Output the answer.
5 5 20
2 2 0 2 0
2 2 0
2 0 2
3 0 2 0
3 0 2 0
2 2 2
10
2 1 5 5 2 2 4 2 5 3
6
10 10 10000
0 1 1 1 0 1 1 0 0 0
6 0 0 1 1 1 0
6 0 0 0 0 0 0
5 0 0 0 0 0
4 1 0 0 0
5 1 1 1 0 1
2 1 1
6 0 0 0 0 0 1
1 0
4 0 0 1 1
1 1
30
10 4 3 9 10 9 4 8 5 10 9 8 6 10 10 4 9 2 2 9 6 4 1 10 10 1 9 10 3 5
3001
Hint
Explanation for Sample 1

Constraints
For all testdata, , , . The total length of all small strings does not exceed . All characters are in .
| Subtask | Special Properties | ||||
|---|---|---|---|---|---|
| 1 (20 points) | The alphabet is , and the total length of all small strings does not exceed . | ||||
| 2 (30 points) | The alphabet is , , , and the total length of all small strings does not exceed . | ||||
| 3 (10 points) | The alphabet is , , . | ||||
| 4 (40 points) |
Translated by ChatGPT 5
京公网安备 11011102002149号