답안 #83615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83615 2018-11-09T13:39:43 Z charlies_moo Mate (COCI18_mate) Python 2
0 / 100
20 ms 3864 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
    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)]

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

for ans in arr_r:
    print ans

# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 2936 KB Execution failed because the return code was nonzero
2 Runtime error 14 ms 2972 KB Execution failed because the return code was nonzero
3 Runtime error 15 ms 3036 KB Execution failed because the return code was nonzero
4 Runtime error 14 ms 3060 KB Execution failed because the return code was nonzero
5 Runtime error 14 ms 3112 KB Execution failed because the return code was nonzero
6 Runtime error 14 ms 3112 KB Execution failed because the return code was nonzero
7 Runtime error 14 ms 3112 KB Execution failed because the return code was nonzero
8 Runtime error 14 ms 3112 KB Execution failed because the return code was nonzero
9 Runtime error 19 ms 3864 KB Execution failed because the return code was nonzero
10 Runtime error 20 ms 3864 KB Execution failed because the return code was nonzero