Problem:


Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))

mod=998244353

from collections import Counter
C=Counter(D)

FACT=[1]
for i in range(1,2*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0


if C[0]!=1:
    print(0)
    sys.exit()

MAX=max(D)

for i in range(MAX):
    if C[i]==0:
        print(0)
        sys.exit()

ANS=1

for i in range(1,MAX+1):
    ANS=ANS*pow(C[i-1],C[i],mod)%mod

print(ANS)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353


X = defaultdict(int)
for d in D:
    X[d] += 1


ans = 1
for d in D:
    if d == 0:
        continue

    ans *= X[d - 1]
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))

MOD = 998244353

if D[0] != 0:
  print(0)
  exit()

M = max(D)
T = [0] * M

for i in range(1, N):
  T[D[i] - 1] += 1

if D[0] != 0:
  print(0)
  exit()

for i in range(1, M):
  if T[i] == 0:
    print(0)
    exit()

ans = 1
for i in range(1, M):
  ans = ans * (T[i - 1] ** T[i]) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

D = list(map(int,input().split()))

D.sort()

lis = [0] * (10 ** 5 + 1)

ans = 0
for i in D:

    if i == 0 and ans == 0:
        lis[i] += 1
        ans += 1

    elif i == 0 and ans != 0:
        ans = 0

    else:

        lis[i] += 1
        ans *= lis[i-1]
        ans %= 998244353

    
print (ans%998244353)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 998244353

def solve():
    n = I()
    d = LI()
    f = defaultdict(lambda : 0)
    for i in d:
        f[i] += 1
    m = max(d)
    ans = 1
    for i in range(m):
        ans *= pow(f[i],f[i+1],mod)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
k=[int(i)for i in input().split()[1:]]
p=1
for i in k:
    p*=i
print(p)

Submission status: Wrong Answer

Solution code:

N = int(input())

D = list(map(int,input().split()))

D.sort()

lis = [0] * (10 ** 5 + 1)

ans = 0
for i in D:

    if i == 0 and ans == 0:
        lis[i] += 1
        ans += 1

    elif i == 0 and ans != 0:
        ans = 0

    else:

        lis[i] += 1
        ans *= lis[i-1]

    
print (ans)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
DD = inpl()
cnts = [0]*N
m = -1
for d in DD:
    cnts[d] += 1
    m = max(d,m)

if cnts[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1,m+1):
        ans *= pow(cnts[i-1],cnts[i],mod)
        ans %= mod
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353


def solve(n,d):
    if d[0] != 0:
        return 0
    dc = Counter(d)
    if dc[0] > 1:
        return 0
    res = 1
    k = 1
    while k <= max(d):
        res *= dc[k-1]**dc[k]
        res %= MOD
        k += 1
    return res


def main():
    N = int(input())
    d = list(map(int,input().split()))
    # N,M = map(int,input().split())
    print(solve(N,d))


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353


def solve(n,d):
    if d[0] != 0:
        return 0
    dc = Counter(d)
    if dc[0] > 1:
        return 0
    res = 1
    k = 1
    while k <= max(d):
        res *= dc[k-1]**dc[k]
        res %= MOD
        k += 1
    return res


def main():
    N = int(input())
    d = list(map(int,input().split()))
    # N,M = map(int,input().split())
    print('{}'.format(solve(N,d)))


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))

a = [0] * n
for i in range(n):
    a[d[i]] += 1

if a[0] == 1 and d[0] == 0:
    ans = 1
    for i in range(1, n):
        ans *= a[i-1]**a[i]

    print(ans % 998244353)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))

if D[0] != 0:
    print(0)
    exit()

for i in range(max(D)):
    if i not in D:
        print(0)
        exit()

A = collections.Counter(D)
A = list(A.items())
A.sort()
ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
    if ans >= 998244353:
        ans %= 998244353
print(ans)

Submission status: Time Limit Exceeded

Solution code:
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit()
lis = []
for i in range(n):
    lis.append(d.count(i))
if lis[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, n):
    ans *= pow(lis[i-1], lis[i], mod)
    ans %= mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
if a[0] > 0 or a.count(0) > 1:
  print(0)
  exit()
  
a = sorted(a)
dp = [0]*(n+1)
dp[0] = 1
count_list = [0]*n
count_list[0] = 1
for i in range(1, n):
  num = a[i]
  count_list[num] += 1
  dp[a[i]] = dp[num-1] * count_list[num-1] ** count_list[num] % 998244353
print(dp[a[n-1]])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
if a[0] > 0 or a.count(0) > 1:
  print(0)
  exit()
  
a = sorted(a)
dp = [0]*(n+1)
dp[0] = 1
count_list = [0]*n
count_list[0] = 1
for i in range(1, n):
  count_list[a[i]] += 1
  dp[a[i]] = dp[a[i]-1] * count_list[a[i]-1] ** count_list[a[i]] % 998244353
print(dp[a[n-1]])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

count_dict = {}
for i in range(n):
    count_dict[i] = 0
for val in d_l:
    count_dict[val] += 1

if d_l[0] != 0 or count_dict[0] != 1:
    ans = 0
else:
    ans = 1

for i in range(1,n):
    ans = ans*(count_dict[i-1]**count_dict[i])
    if ans == 0:
        break

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

d_l.sort()
d_l = d_l[1:]
count_l = [1,]

for i in range(1,n):
    count_l.append(d_l.count(i))
    d_l = d_l[count_l[i]:]
    ans = (ans*(count_l[i-1]**count_l[i]))%998244353
    if d_l == [] or ans == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

d_l.sort()
d_l = d_l[1:]
count_l = [1,]

for i in range(1,n):
    count_l.append(d_l.count(i))
    d_l = d_l[count_l[i]:]
    ans = ans*(count_l[i-1]**count_l[i])
    if d_l == [] or ans == 0:
        break

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

n_tmp = n-1
count_l = [1,]

for i in range(1,n):
    count_l.append(d_l.count(i))
    ans = ans*(count_l[i-1]**count_l[i])%998244353
    n_tmp -= count_l[i]
    if n_tmp == 0 or ans == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

count_l = [0] * n
for i in range(n):
    count_l[i] = d_l.count(i)

if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

n_tmp = n-1
for i in range(1,n):
    ans = ans*(count_l[i-1]**count_l[i])%998244353
    n_tmp -= count_l[i]
    if n_tmp == 0:
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))

count_l = [0] * n
for i in range(n):
    count_l[i] = d_l.count(i)

if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

n_tmp = n-1
for i in range(1,n):
    ans = ans*(count_l[i-1]**count_l[i])
    n_tmp -= count_l[i]
    if n_tmp == 0:
        break

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_l = list(map(int,input().split()))


if d_l[0] != 0 or d_l.count(0) != 1:
    ans = 0
else:
    ans = 1

n_tmp = n-1
for i in range(1,n):
    n_tmp2 = d_l.count(i-1)
    n_tmp3 = d_l.count(i)
    ans = ans*(n_tmp2**n_tmp3)
    n_tmp -= n_tmp3
    if n_tmp == 0:
        break

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0] != 0:
  print(0)
  exit()
ans = 1
A = []
for i in range(max(D)+1):
  A.append(D.count(i))
for i in range(max(D)+1):
  if A[i] == 0:
    print(0)
    exit()
  if i > 0:
    ans *= pow(A[i-1], A[i], mod) % mod
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0] != 0:
  print(0)
  exit()
ans = 1
A = []
for i in range(max(D)+1):
  A.append(D.count(i))
for i in range(max(D)+1):
  if A[i] == 0:
    print(0)
    exit()
  if i > 0:
    ans *= pow(A[i-1], A[i], mod)
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0] != 0:
  print(0)
  exit()
ans = 1
for i in range(max(D)+1):
  if D.count(i) == 0:
    print(0)
    exit()
  if i > 0:
    ans *= pow(D.count(i-1), D.count(i), mod)
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int( input() )
tree = list( map( int, input().split() ) )

c = Counter(tree)
if tree[0] != 0 or c[0] != 1:
    print(0)
else:
    ans = 1
    a = c[0]
    for i in range( 1,N):
        t = c[i]
        # print(i,a,t,a**t)
        ans *= ( a**t )
        a = t
    print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n,*d=map(int,open(0).read().split())
  e=[0]*n
  for i in d:e[i]+=1
  a=1if d[0]<1else 0
  for i in d[1:]:a*=e[i-1]
  print(a%998244353)
main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
counter = [0] * N
for d in D:
    counter[d] += 1

if counter[0] != 1:
    print(0)
    exit()

ans = 1
for d in D[1:]:
    ans *= counter[d-1] % mod
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if  l[0]!=0:
    print(0)
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]

print(res%MOD)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if dp[0] != 1 and l[0]!=0:
    print(0)
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]

print(res%MOD)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if dp[0] != 1:
    print(0)
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]

print(res%MOD)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = [int(i) for i in input().split()]

if d[0] != 0 or d.count(0) > 1:
    print(0)
    exit()

ans = 1
for i in range(1, max(d) + 1):
    ans *= d.count(i - 1) ** d.count(i)

print(ans % 998244353)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

X = 998244353
N = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    ans = 0
elif N == 1:
    ans = 1
else:
    ans = 1
    Dd = deque(D)
    Dc = [Dd.count(i) for i in range(0, max(D)+1) ]

    if Dc[0]>1 or not all(Dc[1::]):
        ans = 0
    else:
        n1 = 1
        for n2 in Dc[1::]:
            nn = (n1**n2)%X
            ans *= nn
            n1 = n2
        ans%=X
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_1 = input().split()
d = [int(s) for s in d_1]

if d[0] != 0:
  print(0)
else:
  M = max(d) + 1
  ans = 1
  for i in range(M-2):
    ans = ans * pow(d.count(i+1), d.count(i+2), 998244353) % 998244353
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=list(map(int,input().split()))
p=0
if D[0]!=0:
    print(0)
else:
    for i in range(N):
        if p<=D[i]:
            p=D[i]
        else:
            p=p
 
    List=[]
    for i in range(p+1):
         y=0
         for j in range(N):
            if D[j]==i:
                y=y+1
            else:
                y=y
         List.append(y)
    
    t=0
    for i in range(p):
         if List[i]==0:
             t=t+1
         else:
             t=t
 
    if t!=0:
        print(0)
    elif List[0]!=1:
         print(0)
    else:
        count=1
        for i in range(p):
             count=count*(List[i]**List[i+1])
        print(count%998244353)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=list(map(int,input().split()))
p=0
if D[0]!=0:
    print(0)
else:
    for i in range(N):
        if p<=D[i]:
            p=D[i]
        else:
            p=p

    List=[]
    for i in range(p+1):
         y=0
         for j in range(N):
            if D[j]==i:
                y=y+1
            else:
                y=y
         List.append(y)
    
    t=0
    for i in range(p):
         if List[i]==0:
             t=t+1
         else:
             t=t
 
    if t!=0:
        print(0)
    elif List[0]!=1:
         print(0)
    else:
        count=1
        for i in range(p):
             count=count*(List[i]**List[i+1])
        print(count%998244353)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
q=[]
#from collections import Counter
#q=Counter(d)

for i in range(max(d)+1):
    q.append(d.count(i))

if q[0]!=1 or d[0]!=0:
    print(0)
    exit()

ans=1
for i in range(1,max(d)+1):
    ans*=q[i-1]**q[i]
    if ans == 0:
        break
print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0:
        print(0)
        exit()
    Dnum = [0 for _ in range(N)]
    for i in D:
        Dnum[i] += 1
    if Dnum[0] != 1:
        print(0)
        exit()
    ans = 1
    num = 0
    for i in range(N-1):
        if num == N:
            break
        else:
            ans *= Dnum[i] ** Dnum[i+1]
    print(ans%998244353)


if __name__ == '__main__': main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0:
        print(0)
        exit()
    Dnum = [0] * N
    for i in D:
        Dnum[i] += 1
    if Dnum[0] != 1:
        print(0)
        exit()
    ans = 1
    num = 0
    for i in range(N-1):
        if num == N:
            break
        else:
            ans *= Dnum[i] ** Dnum[i+1]
    print(ans%998244353)


if __name__ == '__main__': main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=list(map(int,input().split()))
ans=1
if D[0]!=0:
    print(0)
else:
    for i in range(max(D)-1):
        ans*=D.count(i+1)**D.count(i+2)
        if ans==0:
            break
    print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D=list(map(int,input().split()))
ans=1
if D[0]!=0:
    print(0)
else:
    for i in range(max(D)-1):
        ans*=D.count(i+1)**D.count(i+2)
        ans%=998244353
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
  print(0)
else:
  M = max(D)
  z = 0
  L = []
  for u in range(M+1):
    s = 0
    for v in range(1, len(D)):
      if D[v] == u:
        s += 1
    L.append(s)
  if L[0] != 0:
    print(0)
  else:
    P = 1
    for x in range(1, len(L)-1):
      P = (P * (L[x] ** L[x+1])) % 998244353
    print(P)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
d = [int(s) for s in input().split()]
if d[0] != 0:
    print(0)
    quit(0)
c = Counter(d)
if c[0] != 1:
    print(0)
    quit(0)
print(reduce(lambda x, y: x * y, (c[x - 1] for x in d[1:]), 1) % 998244353)

Submission status: Time Limit Exceeded

Solution code:
n,*d=map(int,open(0).read().split())
e=[0]*n
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Submission status: Time Limit Exceeded

Solution code:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*10**5
for i in d:e[i]+=1
a=d[0]<1==e[0]
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
 
output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        output *= pow(a.count(i-1),a.count(i),998244353)
        output %= 998244353
    print(output)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=1
x=max(a)
if a[0]!=0:
  print(0)
else:
  b=[1]*(x+1)
  for i in range(1,x+1):
    count=(count*(b[i-1]**a.count(i))%998244353)
    b[i]=a.count(i)
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=1
if a[0]!=0:
  print(0)
else:
  b=[1]
  for i in range(1,max(a)+1):
    count=(count*(b[i-1]**a.count(i))%998244353)
    b.append(a.count(i))
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))

x = []
for i in range(max(d)+1):
	x.append(d.count(i))
ans = 1
if d[0] == 0 and x[0] == 1:
	for i in range(1, len(x)-1):
		ans = ans * (x[i]**x[i+1])
else:
	ans = 0

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    cn=[0]*N
    for i in range(N):
        cn[D[i]]+=1

    if D[0]!=0:
        print(0)
    else:
        answer=1
        bak=cn[0]
        kyo=1
        hen=1
        while True:
            if kyo >= N:
                while True:
                    pass
            cnt=cn[kyo]
            hen+=cnt
            if cnt==0:
                break
            answer=answer*baai(bak, cnt)%MOD
            bak=cnt
            kyo+=1
        if hen==N:
            print(answer%MOD)
        else:
            print(0)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))


ans = 1
if d[0] == 0 and d.count(0) == 1:
	for i in range(1, max(d)):
		x = d.count(i)
		ans = ans * (x**(d.count(i+1)))
else:
	ans = 0

print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353


n = INT()
d = MAP()

if d[0]!=0:
    print(0)
    exit(0)

l = [d.count(i) for i in range(max(d)+1)]
ans=1
for i in range(1,max(d)+1):
    ans*=pow(l[i-1],l[i],MOD)
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353


n = INT()
d = MAP()

if d[0]!=0:
    print(0)
    exit(0)

ans=1
for i in range(1,max(d)+1):
    ans*=pow(d.count(i-1),d.count(i),MOD)
    ans %= MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

count = Counter(d)

if d[0] != 0:
    print(0)
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print(0)
    
else:
    ans = 1
    tmp = 1
    len_d = len(d)
    for i in range(1, len_d+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))

count = Counter(d)

if d[0] != 0:
    print(0)
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print(0)
    
else:
    ans = 1
    tmp = 1
    for i in range(1, len(d)+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    
    if d[0] != 0:
        print(0)
        return
    
    count = Counter(d)
    #print(count[0])
    #print(len(count))
    #print(count.keys())
    #print(count.items())
    if count[0] != 1:
        print(0)
        return

    ans = 1
    tmp = 1
    for i in range(1, len(d)+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
D = list(map(int, input().split()))
D = np.array(D)


if D[0] != 0:
    print(0)
else:
    D = np.sort(D[1:])
    if sum(D == 0) != 0:
        print(0)
    elif sum(np.diff(np.array(list(set(D)))) != 1) != 0:
        print(0)
    else:
        count = 1
        now_count = 1
        for i in range(max(D)):
            next_count = sum(D == i+1)
            count = count * (now_count ** next_count)
            now_count = next_count
        print(count % 998244353)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D_list = [int(s) for s in input().split(" ")]

res = 1
Dmax = max(D_list)
if (D_list.count(0) == 1) and (D_list[0] == 0):
    for i in range(0, Dmax):
        if D_list.count(i)!=1:
            res *= D_list.count(i) ** D_list.count(i+1)
        else:
            continue
else:
    res = 0

print(res % 998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
m = max(d)
s = set(d)

if d[0] != 0 or s != set(i for i in range(m+1)):
	print(0)
else:
	res = 1
	for i in range(1, m+1):
		res *= d.count(i-1)**d.count(i)
	print(res%998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
dic = {i: d.count(i) for i in range(max(d)+1)}

if d[0] != 0:
	print(0)
else:
	if all(dic[i]>0 for i in range(max(d)+1)):
		res = 1
		for i in range(1, max(d)+1):
			res *= dic[i-1]**dic[i]
		print(res%998244353)
	else:
		print(0)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

n = int(input())
d = list(map(int, input().split()))


if d[0]!=0:
    print(0)
    sys.exit(0)

p=1

for i in range(1,max(d)+1):
        p = (p * pow(d.count(i-1), d.count(i), 998244353))%998244353

print(p)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

n = int(input())
d = list(map(int, input().split()))


if d[0]!=0:
    print(0)
    sys.exit(0)

p=1

for i in range(1,max(d)+1):
    if d.count(i)==0:
        print(0)
        sys.exit(0)
    elif d[i]==0:
        print(0)
        sys.exit(0)
    else:
        p = (p * pow(d.count(i-1), d.count(i), 998244353))%998244353

print(p)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
d = list(map(int, input().split()))

if d[0] != 0:
    print(0)
    exit()

cnt = Counter(d)

if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for i in d:
    if i != 0:
        ans *= cnt[i-1] % 998244353
print(ans % 998244353)

Submission status: Time Limit Exceeded

Solution code:
#inputは文字列として取得
input1=input()
input2=input()
#splitする必要がある
input2=input2.split(" ")

N=int(input1)
D=[int(s) for s in input2]

ans=None


if D.count(0)==1 and D[0]==0:

    mul=1
    n=1

    for i in range(1,max(D)+1):
        m=D.count(i)
        mul=mul*pow(n,m,998244353)
        n=m
    
    ans=mul%998244353

else:
    ans=0

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
if a[0] != 0 or a.count(0) != 1:
    print(0)
else:
    s = 1
    a.sort()
    list = [0]*n
    t = 0
    s = 0
    k = 1
    for i in range(n):
        if a[i] == t:
            s += 1
        if a[i] != t:
            list[t] = s
            t = a[i]
            s = 1
        if i == n-1:
            list[t] = s
    for i in range(n-1):
        k *= list[i] ** list[i+1]
    print(k % 998244353)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max(d)+1):
        dc = d.count(i)
        if dc == 0:
            print(0)
            exit()
        if dc == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dc, 998244353)
        b = dc
    print(ans % 998244353)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
c=[0]*(n+1)
ans=1
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(1,n):
    if ans==0:
      break
    elif c[j]==0 and c[j+1]==0:
      ans+=0
    else:
      ans*=c[j-1]**c[j]
      
  print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
D_n = [D.count(i) for i in range(max(D) + 1)]
#print(D_n)
#n1が0ではない、もしくは他に0がある
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    #print(D[i + 1])
    #print(bi)
    if D_n[i] == 0:
      break
    for j in range(D_n[i + 1]):
      ans *= D_n[i]
      ans %= mod
print(ans % mod)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = d.count(y)
  return mem[y]

if d[0] != 0:
  print(0)
  exit()

for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()

count = 1
for i in range(n-1):
  count = count * countd(i) ** countd(i+1)
  count = count % 998244353

print(count)

Submission status: Time Limit Exceeded

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-09 21:20:16(JST)
### modules
## from standard library
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

mod = 998244353

def main():
    n, *d = (int(x) for x in sys.stdin.read().split())
    
    if d[0] != 0:
        print(0)
        exit()

    del d[0]

    if 0 in d:
        print(0)
        exit()

    d.sort()
    
    maximum = d[-1]
    for i in range(1, maximum + 1):
        if not i in d:
            print(0)
            exit()


    c = collections.Counter(d)
    
    total =  1
    for b, e in sorted(c.items()):
        if b != maximum:
            nex = c[b+1]
            total *= e ** nex % mod
    print(total % mod)




if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
c=[0]*(n+1)
ans=1
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(1,n):
    if c[j]==0 and c[j+1]==0:
      ans+=0
    else:
      ans*=c[j-1]**c[j]
      
  print(ans%998244353)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
D_n = [D.count(i) for i in range(max(D) + 1)]
#print(D_n)
#n1が0ではない、もしくは他に0がある
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    #print(D[i + 1])
    #print(bi)
    for j in range(D_n[i + 1]):
      ans *= D_n[i]
      ans %= mod
print(ans % mod)