Submission #84112

# Submission time Handle Problem Language Result Execution time Memory
84112 2018-11-13T03:06:30 Z XBXJLeiLeLeiLe Mate (COCI18_mate) PyPy
80 / 100
2000 ms 45944 KB
s = raw_input().split()[0]
q = input()


length = len(s)+1
arr1 = [[] for i in range(length)]
arr1[0].append(1)


def get_num(row, column):
    num = 0
    if column >= 0:
        num = arr1[row][column]
    return mod(num)

def combination(n, d):
    k = d - 2
    return arr1[n][k]


def mod(num):
    return num % (10**9+7)


def lst_id(letter):
    return ord(letter) - ord("a")

for j in range(1, length):
    for i in range(j):
        arr1[j].append(get_num(j - 1, i - 1) + get_num(j - 1, i))
    arr1[j].append(1)





arr = [[0 for i in range(26)] for i in range(len(s))]
arr_c = [0 for i in range(26)]
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

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 += mod(combination(i, d) * arr[i][lst_id(y)])


    arr_r.append(mod(total))

for ans in arr_r:
    print ans




# Verdict Execution time Memory Grader output
1 Correct 117 ms 19476 KB Output is correct
2 Correct 123 ms 19476 KB Output is correct
3 Correct 106 ms 19644 KB Output is correct
4 Correct 120 ms 20736 KB Output is correct
5 Correct 358 ms 27604 KB Output is correct
6 Correct 393 ms 29908 KB Output is correct
7 Correct 332 ms 29908 KB Output is correct
8 Correct 310 ms 29908 KB Output is correct
9 Execution timed out 2059 ms 45136 KB Time limit exceeded
10 Execution timed out 2066 ms 45944 KB Time limit exceeded