#P5855. 「SWTR-3」Password
「SWTR-3」Password
Background
Little found a treasure chest in a dense forest.
The chest has a combination lock, but little does not know the password.
Problem Description
The password of the chest consists of digits. If you write them together, it can be seen as a string of length .
Little wants to guess the password. For each digit position, there is a set , representing the range of digits little will try for the -th position.
Also, little has already tried password strings . These passwords do not necessarily satisfy the above “try ranges”.
Little wants to know the maximum number of additional attempts he may still need to crack the chest’s password. If he can never crack it, output .
Input Format
The first line contains two integers .
The second line contains a string of length , representing the chest’s password.
In the next lines, each line starts with an integer , indicating the size of , followed by a string of length . It is guaranteed that all digits in are distinct.
In the next lines, each line contains a distinct string of length , indicating the password strings that little has already tried.
Output Format
Output the maximum number of additional attempts little may still need to crack the chest’s password. If he can never crack it, output .
3 2
094
2 01
3 149
2 45
145
345
11
2 1
12
2 12
2 34
13
-1
6 10
907887
9 295064731
6 796350
9 295378410
5 48520
9 745208361
7 8079632
111664
422880
521471
433649
037388
091076
235569
979229
268527
690028
153085
18 10
869813962161100526
7 1762348
8 13948756
6 542169
8 78314952
6 432601
9 697130845
8 16358709
8 95204367
8 24079563
6 145602
7 6231549
6 157096
8 62534170
5 82390
7 5396702
8 20536491
7 1438692
5 59261
396440170984129947
891187409797339137
626815840963841542
192230179244843846
148170753474901744
142718603216393332
486224779191226121
819116507635433912
879948053659796486
875405657525125039
1468282385203195
Hint
Sample Explanation
-
In sample , the possible password strings little may try are:
014,015,044,045,094,095,114,115,144,145,194,195, a total of strings. This set contains the real password, but since145has already been tried, little may need at most more attempts. -
In sample , the possible password strings little may try are:
13,14,23,24, a total of strings. None of them is the real password, so little can never crack the password.
Constraints and Notes
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| The answer is | |||
| None | |||
| None |
For of the data, and .
It is guaranteed that is not the password.
For all test points, the time limit is and the memory limit is .
Translated by ChatGPT 5