#P6540. [COCI 2013/2014 #1] SLASTIČAR
[COCI 2013/2014 #1] SLASTIČAR
Background
You need to compare some serial numbers.
Problem Description
There are short serial numbers consisting of digits to , and one long serial number of length .
The process of checking whether serial number contains a serial number of length is as follows:
-
Compare with digit by digit from positions to . Once a mismatch is found, shift the whole search window one position to the right. If they are confirmed equal, stop comparing.
-
Shifting the search window means moving the search range from to to and .
-
If the remaining digits are not enough for comparison, pad the end of the string with
#. For example, for the string563232, padding from position to becomes232####. -
If all windows have been tried and none matches, stop comparing.
For each short serial number, output the number of comparisons made before the comparison process stops.
Input Format
The first line contains a positive integer .
The second line contains a long serial number of length .
The third line contains a positive integer .
The next lines each contain a short serial number of length at most .
The total length of all short serial numbers does not exceed .
Output Format
Output integers. The -th integer is the number of comparisons needed for the -th short serial number.
7
1090901
4
87650
0901
109
090
7
10
3
4
10
5821052680
4
210526
2105
582
105268
8
6
3
9
3
001
1
11
4
Hint
Constraints
- For of the testdata, , , and the length of every short serial number is at most .
- For of the testdata, and .
- For any character in any serial number, .
Sample Explanation
Sample 1 Explanation
The first serial number:
- The robot looks for the first different digit in each window, making a total of comparisons.
The second serial number:
- Try the first position, immediately finds a mismatch: comparison.
- Try the second position, finds a mismatch at the fourth digit: comparisons.
- Try the third position, immediately finds a mismatch: comparison.
- Try the fourth position, finds a match: comparisons.
- Total: comparisons.
The third serial number:
- Immediately finds a match, total comparisons.
The fourth serial number:
- Finds a match at the second position, total comparisons.
Sample 3 Explanation
Compare serial number 11 with window 00 in order: comparison, then 01: comparison, and 1#: comparisons, for a total of comparisons.
Notes
This problem is translated from COCI2013-2014 CONTEST #1 T6 SLASTIČAR.
Translated by ChatGPT 5