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://codeforces.me/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]))↵
~~~~~↵
↵
This is my code for https://codeforces.me/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]))↵
~~~~~↵
↵