시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 64 MB | 105 | 45 | 39 | 45.882% |
JOI Laboratory has 2L poisonous snakes. The snakes are numbered 0, 1, . . . , 2L − 1. Each snake is divided into L parts from the head to the tail. The color of each part is either blue or red. For the poisonous snake i, let i = \(\sum_{k=1}^{L}\)ck2L−k (0 ≤ ck ≤ 1) be the binary expression of i. Then,
Each poisonous snake has an integer between 0 and 9, inclusive, called the toxicity. A string S of length 2L consisting of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 is given. The i-th character (1 ≤ i ≤ 2L) is the toxicity of the poisonous snake i − 1.
Since poisonous snakes are quick, they often escape from JOI Laboratory. Complaints are given to JOI Laboratory by people living near the laboratory who saw poisonous snakes escaping from the laboratory.
You are given a list of complaints for Q days. The complaints for the d-th day (1 ≤ d ≤ Q) is a string Td of length L consisting of 0, 1, ?.
All the complaints are precise information. All the poisonous snakes escaping from the laboratory were kept by the staffs of JOI Laboratory on the same day. It may happen that the same snake escapes on a different day.
In order to estimate the risk of escaping poisonous snakes, Professor K, the executive director of JOI Laboratory, wants to know the sum of toxicities of the snakes which might escape from the laboratory. Your task is to write a program which calculates, given the list of complaints for Q days, the sum of toxicities of the snakes which might escape from the laboratory for each day.
Given the string S describing the toxicities of the poisonous snakes and the list of complaints for Q days, write a program which calculates the sum of toxicities of the snakes which might escape from the laboratory for each day.
Note that the memory limit is small for this task.
Read the following data from the standard input.
Write Q lines to the standard output. The d-th line should contain an integer, the sum of toxicities of the snakes which might escape from the laboratory on d-th day.
번호 | 배점 | 제한 |
---|---|---|
1 | 5 | L ≤ 10, Q ≤ 1 000. |
2 | 7 | L ≤ 10. |
3 | 10 | L ≤ 13. |
4 | 53 | Q ≤ 50 000. |
5 | 25 | There are no additional constraints. |
3 5 12345678 000 0?? 1?0 ?11 ???
1 10 12 12 36
In this sample input, L = 3. There are 23 = 8 poisonous snakes. Each of them is divided into 3 parts. The complaints are given for 5 days.
4 8 3141592653589793 0101 ?01? ??1? ?0?? 1?00 01?1 ??10 ????
9 18 38 30 14 15 20 80