Number Plates
Simon is in charge of a top secret spy network. Often when you’re a spy, you are yourself spied upon. Simon’s enemies usually spy on him from their cars, but unfortunately he doesn’t know what cars they are in.
For every car he sees, he records its number plate on his cell phone. If he’s been seeing a certain number plate very often recently, there’s a good chance the car is being used to spy on Simon. Thus, he needs you to implement a program that tells him how many times he’s seen a certain number plate.
However, there is an additional complication. Simon can sometimes only see a partial plate, for example when the car he is observing is moving very fast. In this case, he wants to know the total number of times he’s seen all the plates that match the partial plate.
A number plate is a string of exactly 6 digits $0-9$. We say that a new observed plate $X$ matches a previously observed plate $Y$, if for every possible plate that $Y$ could have been, it is also possible that $X$ could be that plate. In particular, if Simon observes the new plate 00x000, it will not match a previously observed plate 00xx00, since the latter could have been 000100 while the new plate could not. However, if 00xx00 was the new plate and 00x000 was the old they would have matched.
Example
Say that the first plate Simon sees is 000000. The answer is $0$, since he’s never seen a plate before. The next plate is yet again 000000, which he has seen once before. Thus the answer is $1$. The third plate he sees is 001000, which he has never seen, making the answer $0$. The fourth plate he sees is only partial: 00x000, where x denotes a digit he didn’t see. This can match both the plates he’s previously seen, so in this case the answer is $3$. The fifth plate he sees is also partial: 00xx00. Note that this partial plate matches partial plate Simon just saw - the partial plate should then be included as well (making the answer $4$). Finally, Simon sees 00x000, which matches $4$ previous plates (see the explanation above).
Task
Given all the plates (either partial or complete) that Simon sees, determine how many of the plates he’ve seen before could match the plate he just saw.
You should implement this as the function plate(P).
-
plate(P) - this function will be called for every plate that Simon sees.
-
P: an array with exactly 6 elements, where P[i] denotes the $i$:th digit in the plate Simon saw. If he didn’t see the $i$:th digit, it will instead be $-1$.
-
The function should return the number of previous plates that this one could match.
-
A code skeleton containing the function to be implemented, together with a sample grader, can be found at http://progolymp.se/uploads/kattis-attachments/regskylt.zip.
Subtasks
The problem consists of a number of subtasks. Each subtask gives some amount of points, and to pass the subtask you must pass all the test cases in the subtask.
Let $P$ be the number of calls to plate.
Subtask |
Points |
Limits |
1 |
13 |
$P \le 100\, 000$, $P[i] \not= -1$ |
2 |
31 |
$P \le 100\, 000$, $P[i]$ is either $0$ or $-1$ |
3 |
20 |
$P \le 1\, 000$ |
4 |
36 |
$P \le 100\, 000$ |
Input format
The sample judge reads input in the following format:
-
line $1$: N - the number of plates.
-
lines $2$ to $2 + N - 1$: P[0] P[1] .. P[5]
Output format
For every plate, the judge writes a line with the return value of plate(P).
Sample Input 1 | Sample Output 1 |
---|---|
6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 -1 0 0 0 0 0 -1 -1 0 0 0 0 -1 0 0 0 |
0 1 0 3 4 4 |