Can anyone help me here?

Revision en1, by New_and_simple, 2024-12-17 13:17:02

As you can probably tell, I am not very good at coding, so I might have made basic errors This is my code for https://mirror.codeforces.com/gym/102942/problem/E Can someone tell me what I am doing wrong? im using PyPy3 64 bit interpreter ~~~~~ import math

t = int(input()) n = [] s = [] for _ in range(t): n.append(int(input())) s.append(input())

def password(n, s): dict = {} j = 0

for i in s:
    if i != '-':
        dict[j] = int(i)
    j += 1

indices = list(dict.keys())
z = [dict[p] for p in indices]

if z:
    if z != sorted(z):
        return 0
    else:
        def permutation(space, value):
            return math.factorial(space + value - 1) // (math.factorial(space) * math.factorial(value - 1))

        k = len(indices)
        ways = 1

        for x in range(k - 1):
            ways *= permutation(indices[x + 1] - indices[x] - 1, dict[indices[x + 1]] - dict[indices[x]] + 1)

        ways *= permutation(indices[0], dict[indices[0]])

        ways *= permutation(n - 1 - indices[k - 1], 10 - dict[indices[k - 1]])

        return ways % ((10 ** 9) + 7)
else:
    return 9 ** n % ((10 ** 9) + 7)

for i in range(t): print(password(n[i], s[i])) ~~~~~

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English New_and_simple 2024-12-17 13:20:26 3 Tiny change: 'erpreter\n~~~~~\ni' -> 'erpreter\n\n~~~~~\ni'
en1 English New_and_simple 2024-12-17 13:17:02 1347 Initial revision (published)