# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
83554 | XBXJLeiLeLeiLe | Mate (COCI18_mate) | Cpython 2 | 2060 ms | 21060 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
s = raw_input()
q = input()
def combination(n, d):
k = d - 2
result = 1
for i in range(k):
result*=n
n-=1
for i in range(k):
result/=k
k-=1
return result
for i in range(q):
d, xy = raw_input().split()
d = int(d)
x = xy[0]
y = xy[1]
arr_l = []
arr_c = []
a = -1
b = -1
if x != y:
for i in range(len(s)):
if i >= d - 2 and s[i] == x:
arr_l.append(i)
arr_c.append(0)
a = i
b += 1
elif len(arr_l)>0 and s[i]==y and i > a:
for k in range(len(arr_c)):
arr_c[k] += 1
for j in range(len(arr_l)):
arr_l[j] = combination(arr_l[j], d)
total = 0
for i in range(len(arr_l)):
total += arr_l[i]*arr_c[i]
print total
else:
for i in range(len(s)):
if i >= d - 2 and s[i] == x:
arr_l.append(i)
for k in range(len(arr_c)):
arr_c[k] += 1
arr_c.append(0)
for j in range(len(arr_l)):
arr_l[j] = combination(arr_l[j], d)
total = 0
for i in range(len(arr_l)):
total += arr_l[i]*arr_c[i]
print total
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |