s = raw_input()
q = input()
def combination(n, d):
k = d - 2
if n - k < k:
k = n - k
result = 1
for i in range(k):
result *= n
n -= 1
w = k
for i in range(w):
result /= k
k -= 1
return result
def mod(num):
return num % (10**9+7)
def lst_id(letter):
return ord(letter) - ord("a")
arr = [[0 for i in range(26)] for i in range(len(s))]
arr_c = [0 for i in range(26)]
try:
for i in range(len(s)-1, -1, -1):
for j in range(26):
arr[i][j] = arr_c[j]
arr_c[lst_id(s[i])] += 1
except:
pass
arr_r = []
for i in range(q):
d, xy = raw_input().split()
total = 0
d = int(d)
x = xy[0]
y = xy[1]
for i in range(len(s)):
if s[i] == x and i >= d - 2:
total += combination(i, d) * arr[i][lst_id(y)]
arr_r.append(mod(total))
for ans in arr_r:
print ans
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
181 ms |
16912 KB |
Output isn't correct |
2 |
Incorrect |
171 ms |
16912 KB |
Output isn't correct |
3 |
Incorrect |
153 ms |
16912 KB |
Output isn't correct |
4 |
Incorrect |
197 ms |
18656 KB |
Output isn't correct |
5 |
Execution timed out |
2045 ms |
20312 KB |
Time limit exceeded |
6 |
Execution timed out |
2048 ms |
20980 KB |
Time limit exceeded |
7 |
Execution timed out |
2057 ms |
20980 KB |
Time limit exceeded |
8 |
Execution timed out |
2074 ms |
20980 KB |
Time limit exceeded |
9 |
Execution timed out |
2055 ms |
20980 KB |
Time limit exceeded |
10 |
Execution timed out |
2070 ms |
20980 KB |
Time limit exceeded |