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:
n = int(input())
list1 = list(map(int,input().split()))


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]
count *= list2[-1]
print(count%998244353)

Submission status: Wrong Answer

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):
        print(0)
    else:
        print(np.prod(D) % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 1
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_max = max(d_l)
    count_dic = collections.Counter(d_l)
    if count_dic[0] != 0:
        print(0)
        sys.exit()
    
    for i in range(2, d_max+1):
        ans *= count_dic[i-1] ** count_dic[i]
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353
B = [v for k, v in sorted(Counter(A).items())]
if A[0] != 0 or not all(A[1:]) or not all(B):
    print(0)
else:
    t = r = 1
    for b in B:
        t *= pow(r, b, MOD) % MOD
        r = b
    print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    #ans = ans * pow(num[i-1], num[i], 998244353)%998244353
    ans*=num[i-1]**num[i]

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

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 1
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_max = max(d_l)
    count_dic = collections.Counter(d_l)
    if count_dic[0] != 0:
        print(0)
    
    for i in range(2, d_max+1):
        ans *= count_dic[i-1] ** count_dic[i]
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=[int(i) for i in input().split()]
if d[0]!=0:
    print(0)
else:
    ans=1
    m=max(d)
    cnt=[0]*(10**5+1)
    for i in d:
        cnt[i]+=1
    for i in range(1,m+1):
        ans*=pow(i,cnt[i])
        ans%=998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

mod = 998244353

set_d = set(d)
list_d = list(set_d)
list_d.sort()
dict_d = Counter(d)

if dict_d[0] == 1:
    pass
else:
    print(0)
    exit()

ans = 1
cnt = 1
temp = -1
check = 1

for i in list_d:

    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = (ans * (check**cnt))%mod
    check = cnt
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
top=D.pop(0)
if top!=0:print(0);exit()
D_count=sorted(Counter(D).items())
ans=1
for i in range(1,max(D)):
    if D_count[i-1]==i:
        ans *=(D_count[i][1]**D_count[i+1][1])%998244353
    else:
        print(0)
        exit()
print(ans)

Submission status: Wrong Answer

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

L = [0]*(n)
for a in A :
  L[a] += 1

if L[0] != 0 :
  print(0)
else :
  flg = 0
  for a in A[1:] :
    if a == 0 :
      if flg == 0 :
        flg = 1
      else :
        print(0)
        exit()
    else :
      flg = 1
  
  ans = 1
  for a in A[1:] :
    if a == 0 :
      print(ans)
      exit()
    else :
      ans *= a
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    ans = ans * pow(num[i-1], num[i], 998244353)%998244353
    #ans*=num[i-1]**num[i]

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0)

    else:

        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        if len(items) == 1:
            print(0)

        else:
            ans = 1
            tmp = 1
            for i,j in items:
                if i == 0:
                    if j >= 2:
                        ans = 0
                        break
                    tmp = j
                    tmp_i = i
                    continue

                ans *= tmp**j
                #print(ans)
                tmp = j

            print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx == 0:
        count *= 1
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree

if tree_list[0] != 1:
    print(0)
    quit()
else:
    print(int(count%998244353))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(map(int,input().split()))
if s[0] != 0:
  print(0)
  exit()
ans = 1
for i in range(1,n):
  ans *= s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
 
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
m = max(cnt)
for i in range(m):
  if not i in cnt:
    print(0)
    exit()
try:
  if cnt[0]==1:
    ans = 1
    for i in range(m):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD
 
    print(ans%MOD)
  else:
    print(0)
except KeyError:
  print(0)
  exit()
#なんでACにならないのか・・・
#例外処理が足りてないのか....
#0が複数個orなしのときは書いた
#

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D)+1)]
for n in range(N):
    new_l[D[n]] += 1
if new_l[0] == 1 and D[0] == 0:
    res = 1
    for n in range(max(D)):
        res *= pow(new_l[n],new_l[n+1],998244353)
    print(res%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
Ds = list(map(int, input().split()))
Dsi = [[Ds[i], i+1] for i in range(n)]
length = max(Ds) + 1
Pts = list()

Dsi = sorted(Dsi)
# print(Dsi, 'Dsi', 'Ds', Ds)


start = 0
Iss = list()
# print(length)
for i in range(length):
    Is = list()

    #距離がiであるようなヤツを探す
    for j in range(start, n):

        # print(i, j)
        if Dsi[j][0] == i:
            Is.append(Dsi[j][1])
        else:
            start = j
            break

    
    Iss.append(Is)

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


for i in range(len(Iss)):
    if i == 0:
        if not Iss[i]:
            Pts.append(0)
        else:
            Pts.append(math.factorial(len(Iss[i])))
    else:
        m = len(Iss[i])
        n = len(Iss[i-1])
        if m < n or m <= 1 or n <= 1:
            Pts.append(m**n * Pts[i-1])

            # print(i, Pts[i], 'bbb', m, n)
        else:
            st_p = permutations_count(m - 1, n-1) 
            r_p  = math.factorial(m) * math.factorial(n)

            Pts.append(st_p * r_p * Pts[i-1])
            
            # print(i, Pts[i], 'aaa', m, n)
print(Pts[-1])
# print('iss', Iss)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
top=D.pop(0)
if top!=0:print(0);exit()
D_count=sorted(Counter(D).items())
ans=1
for i in range(len(D_count)-1):
    ans *=(D_count[i][1]**D_count[i+1][1])%998244353
print(ans)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

mod = 998244353

set_d = set(d)
list_d = list(set_d)
list_d.sort()
dict_d = Counter(d)

if dict_d[0] == 1:
    pass
else:
    print(0)
    exit()

ans = 1
cnt = 1
temp = 0
check = 1

for i in list_d:
    if i == 0:
        continue
    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = (ans * (check**cnt))%mod
    check = cnt
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
d=list(map(int,input().split()))
count=1
if d[0]!=0:
    count=0
for i in range(N):
    count *= ((i+1) ** d.count(i+1))
    count = count%99844353
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D)+1)]
for n in range(N):
    new_l[D[n]] += 1
res = 1
if new_l[0] == 1 and D[0] == 0:
    for n in range(len(new_l)-2):
        res *= pow(new_l[n],new_l[n+1],998244353)
    print(res%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
error=0
if num[0]!=1:
    error=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    ans = ans * pow(num[i-1], num[i], 998244353)%998244353
    #ans*=num[i-1]**num[i]
    if num[i]==0:
        error=1
if error==0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]

print(count%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
top=D.pop(0)
if top!=0:print(0);exit()
D_count=sorted(Counter(D).items())
ans=1
for i in range(len(D_count)-1):
    ans *=D_count[i][1]**D_count[i+1][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter 
import sys

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

mod = 998244353
D.sort()
d = list(Counter(D).items()) 

if d[-1][0] != len(d) - 1:
    print(0)
    sys.exit()
if d[0][1] != 1:
    print(0)
    sys.exit()
ans = 1   
for i in range(1,len(d)):
    for _ in range(d[i][1]):
        ans = ((ans * d[i-1][1]) % mod)
    
print(ans)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]

print(count)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==0:
		print(0)
		exit()
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
error=0
if num[0]!=1:
    error=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    ans = ans * pow(num[i-1], num[i], 998244353)
    #ans*=num[i-1]**num[i]
    if num[i]==0:
        error=1
if error==0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
 
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
m = max(cnt)
try:
  if cnt[0]==1:
    ans = 1
    for i in range(m):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD
 
    print(ans%MOD)
  else:
    print(0)
except KeyError:
  print(0)
  exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if D[0] != 0:
    print(0)
elif sum(np.diff(np.array(list(set(D)))) != 1):
    print(0)
else:
    print(np.prod(D[1:]) % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D)+1)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = 1
if new_l[0] == 1 and D[0] == 0:
    for n in range(len(new_l)-1):
        res *= pow(new_l[n],new_l[n+1],998244353)
    print(res%998244353)
else:
    print(0)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0 or d.count(0) >= 2:
  print("0")
else:
  ans = 1
  d.remove(0)
  for i in range(len(d)):
    ans *= d[i]
  print(ans)

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx == 0:
        count *= 1
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
if len(tree_list) == 1 and len(D) > 1:
    print(0)
else:
    print(int(count%998244353))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
for i in li:
    box[i] += 1
count = 1

if len(box) > 2:
    for i in range(1, len(box)-1):
        count *= (box[i] ** box[i+1]) % 998244353
else:
    count = 1
    
if box[0] != 1:
    count = 0

print(count % 998244353)

Submission status: Wrong Answer

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

dd = defaultdict(int)
m = 0
for i in range(n):
    dd[d[i]] += 1
    m = max(d[i], m)

if d[0] != 0 or dd[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, m + 1):
        ans *= dd[i - 1]**dd[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

M = 998244353
n = int(input())
d = sorted(map(int, input().split()))
counter = Counter(d)

ans = counter[0]
if ans != 1:
    ans = 0
else:
    for i in range(1, d[-1] + 1):
        if counter[i] == 0:
            ans = 0
            break
        if counter[i - 1] > 1:
            m, n = counter[i - 1], counter[i]
            c = m ** n
            ans *= c

print(ans % M)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
MOD = 998244353

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

c = Counter(D)
if c[0] != 1 and D[0] != 0:
    print(0)
    exit(0)
d = max(c)
ans = 1
for i in range(d):
    ans *= pow(c[i], c[i+1], MOD)
    ans = ans % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# from operator import mul
# from functools import reduce
# import itertools

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# def combinations_with_replacement_count(n, r):
#     return combinations_count(n + r - 1, r)

N = int(input())
D_list = list(map(int, input().split()))
 
pattern_dic = {}
zero_flag = 0
ans = 1
if D_list[0] != 0:
    print(0)
else:
    for i in range(1, N):
        pattern_dic[D_list[i]] = pattern_dic.get(D_list[i], 0) + 1
    if 1 in pattern_dic:
        before_num = pattern_dic[1]
        for j in range(2, max(pattern_dic.keys()) + 1):
            if j in pattern_dic:
                ans = (ans * (before_num ** pattern_dic[j])) % 998244353
                before_num = pattern_dic[j]
            else:
                zero_flag = 1
                break
    else:
        zero_flag = 1
 
    if zero_flag == 1:
        print(0)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
vertex_list = list(map(int, input().split()))
vertex_list.sort()
ans = 1
mark = 0
if vertex_list[0] != 0:
    print(0)
else:
    maxx = vertex_list[-1]
    for i in range(1,n):
        if vertex_list[i] is not 0 and vertex_list[1]-vertex_list[i-1]<2:
            ans *= vertex_list[i]
        else:
            mark =  1
    if mark == 0:
        print(ans)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

mod = 998244353

N, D1, *D = map(int, open(0).read().split())

if D1 != 0:
    print(0)
    quit()

C = Counter(D)

ans = 1
for i in range(2, max(C.keys(), default=0) + 1):
    ans *= pow(C[i - 1], C[i], mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
#print("n=",n)
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
count = [0 for i in range(n)]
for i in D:
    count[i] = count[i] + 1
if count[0] != 1:
    exit()
#for i in count:
#    print("count",i)
tmp = 1
for i in range(n-1):
#    print(count[i],count[i+1])
    tmp = tmp * (count[i]**count[i+1])
print(tmp%998244353)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D)+1)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = 1
if new_l[0] == 1 and D[0] == 0:
    for n in range(len(new_l)-1):
        res *= new_l[n]**new_l[n+1]
        res %= 998244353
    print(res%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

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

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1

if l[0] != (0, 1):
    answer = 0
elif l[0][1] != 1:
    answer = 0
else:
    for i in range(M-1):
        if l[i][0] + 1 != l[i+1][0]:
            answer = 0
for i in range(M-1):
    answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []
    d = sorted(d)

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for _d in D:
        distance[_d[0]] += 1

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

    if distance[0] != 1:
        print(0)
        return

    # if len(distance) != len([i for i in distance if i != 0]):
    #     print(0)
    #     return

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            ans = ans * n ** r
            ans = ans % MOD
            # print(ans)

    print(ans % MOD)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
MOD = 998244353

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

c = Counter(D)
if c[0] != 1:
    print(0)
    exit(0)
d = max(c)
ans = 1
for i in range(d):
    ans *= pow(c[i], c[i+1], MOD)
    ans = ans % MOD

print(ans)

Submission status: Wrong Answer

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

D.sort()
count = [0]*(D[-1]+1)
ans = 1

if N==1 and D[0] == 0:
    print(1)
    exit()

if D[0] != 0 or D[1] == 0:
    print(0)
    exit()
count[0] = 1
for i in range(N-1):
    if D[i+1]-1 > D[i]:
        print(0)
        exit()
    count[D[i+1]] += 1

for i in range(1,D[-1]+1):
    ans *= count[i-1]**count[i]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D)+1)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = 1
if new_l[0] == 1:
    for n in range(len(new_l)-1):
        res *= new_l[n]**new_l[n+1]
        res %= 998244353
    print(res%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n1 = int(input()) - 1
d = list(map(int, input().strip().split()))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    max_path = max(d)
    flag = True
    v = [0 for i in range(max_path)]
    for i in d[1:]:
        v[i-1] += 1

    if 0 in v:
        flag = False

    if flag:
        num = 1
        hh = 1
        for h in range(len(v)):
            if hh == 1:
                pass
            elif v[h] == 1:
                num *= hh
            else:
                num *= hh * (v[h] + 1)

            hh = v[h]

            num = num % mod

        print(num)

    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
db = [0] * n
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

#末尾に連続する0を削除
if (db[n-1] == 0):
    l = n-1
    for i in range(1,n):
        tmp = db[n-i]
        if (tmp == 0) : l = n-i 
        else : break
    
    del db[l:n]


if (d[0] != 0)|(db[0] != 1):
    print(0)
    exit()
if (len(db) <= 2):
    print(len(db)-1)
    exit()

db.append(1)
ans = 1

for i in range(len(db)-1):
    tmp = (db[i]**db[i+1])
    ans *= tmp

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

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

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx == 0:
        count *= 1
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
if len(tree_list) == 1:
    print(0)
else:
    print(int(count%998244353))

Submission status: Wrong Answer

Solution code:
MOD = 998244353 
N = int(input())
D = [int(x) for x in input().split()]
zero = 0 
for d in D:
    zero += (d == 0)
if (D[0] != 1 or zero != 1):
    print(0)
else:
    lst = [0] * (N)
    for d in D:
        lst[d] += 1
    first0 = False
    for i in range(N):
        if (lst[i] != 0 and first0):
            print(0)
            exit()
        elif (lst[i] ==0):
            first0 = True
    ans = 1
    for i in range(N-1):
        ans *= lst[i] ** lst[i+1]
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
 
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
m = max(cnt)
try:
  if cnt[0]==1:
    ans = 1
    for i in range(m):
      if i not in cnt:
        print(0)
        exit()
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD
 
    print(ans%MOD)
  else:
    print(0)
except KeyError:
  print(0)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1

if l[0] != (0, 1):
    answer = 0
else:
    for i in range(M-1):
        if l[i][0] + 1 != l[i+1][0]:
            answer = 0
for i in range(M-1):
    answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
import sys

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

check = 0
if not check == D[0]:
    print(0)
    sys.exit()
countl = [0]
for d in D:
    if not check == d:
        check += 1
        countl.append(0)
        if not check == d:
            print(0)
            sys.exit()
    countl[-1] += 1
if not countl[0] == 1:
    print(0)
    sys.exit()
if 0 in countl:
    print(0)
    sys.exit()

ans = 1
for i in range(len(countl) - 1):
    ans *= countl[i] ** countl[i + 1]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
vertex_list = list(map(int, input().split()))
vertex_list.sort()
ans = 1
mark = 0
if vertex_list[0] != 0:
    print(0)
else:
    maxx = vertex_list[-1]
    for i in range(1,n):
        if vertex_list[i] is not 0 or vertex_list[1]-vertex_list[i-1]<2:
            ans *= vertex_list[i]
        else:
            mark =  1
    if mark == 0:
        print(ans)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
if D[0]!=0:
    print(0)
else:
    D.sort()
    num_list = []
    cnt=1
    n=0
    for j in range(N-1):
        if D[j]==D[j+1]:
            cnt+=1
            if j==N-2:
                num_list.append(cnt)
        else:
            num_list.append(cnt)
            cnt=1
            n+=1
            if j==N-2:
                num_list.append(1)
    if num_list[0]!=1:
        print(0)
    else:
        len_list = len(num_list)
        if len_list==1:
            print(1)
        elif len_list==2:
            print(num_list[1])
        else:
            S=1
            for m in range(1,len_list-1):
                S = S*(num_list[m]**num_list[m+1])
            print(S%998244353)