Submission #83584

# Submission time Handle Problem Language Result Execution time Memory
83584 2018-11-09T12:21:07 Z XBXJLeiLeLeiLe Mate (COCI18_mate) PyPy
0 / 100
47 ms 11732 KB
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
    for i in range(k):
        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] * 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
    for i in range(len(s)):
        d = int(d)
        x = xy[0]
        y = xy[1]
        if s[i] == x and i > d - 2:
            total += mod(combination(i, d) * arr[i][lst_id(y)])
    arr_r.append(mod(total))
    print mod(total)


# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 11240 KB Execution failed because the return code was nonzero
2 Runtime error 34 ms 11356 KB Execution failed because the return code was nonzero
3 Runtime error 44 ms 11496 KB Execution failed because the return code was nonzero
4 Runtime error 47 ms 11496 KB Execution failed because the return code was nonzero
5 Runtime error 36 ms 11496 KB Execution failed because the return code was nonzero
6 Runtime error 34 ms 11636 KB Execution failed because the return code was nonzero
7 Runtime error 34 ms 11636 KB Execution failed because the return code was nonzero
8 Runtime error 36 ms 11636 KB Execution failed because the return code was nonzero
9 Runtime error 35 ms 11732 KB Execution failed because the return code was nonzero
10 Runtime error 36 ms 11732 KB Execution failed because the return code was nonzero