Submission #83554

# Submission time Handle Problem Language Result Execution time Memory
83554 2018-11-09T07:27:22 Z XBXJLeiLeLeiLe Mate (COCI18_mate) Python 2
0 / 100
2000 ms 21060 KB
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
1 Incorrect 587 ms 4204 KB Output isn't correct
2 Incorrect 346 ms 4204 KB Output isn't correct
3 Incorrect 404 ms 4204 KB Output isn't correct
4 Incorrect 719 ms 4968 KB Output isn't correct
5 Execution timed out 2060 ms 8220 KB Time limit exceeded
6 Execution timed out 2054 ms 9012 KB Time limit exceeded
7 Execution timed out 2059 ms 9012 KB Time limit exceeded
8 Execution timed out 2060 ms 9012 KB Time limit exceeded
9 Execution timed out 2059 ms 20904 KB Time limit exceeded
10 Execution timed out 2058 ms 21060 KB Time limit exceeded