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:
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    d = [int(e) for e in lines[1].split(" ")]

    return (n, d)


def solve(n, d):
    
    d.sort()

    z = [] 
    tmp = d[0]
    count = 0
    for i in range(n):
        if tmp != d[i]:
            z.append((tmp, count))
            tmp = d[i]
            count = 1
        else:
            count = count + 1
    z.append((tmp, count))

    if z[0][0] != 0 or z[0][1] > 1:
        return 0

    result = 1
    m = len(z)
    for i in range(1, m):
        if z[i-1][0] + 1 != z[i][0]:
            result = 0
            break
        else:
            result = result * z[i-1][1] ** z[i][1]

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
else:
  for i in range(1,n-1):
    if d[i] == d[i+1]:
      cnt += 1
    else:
      cnt += 1
      li.append(cnt)
      cnt = 0
    if i == n-2:
      if d[n-2] == d[n-1]:
        cnt += 1
        li.append(cnt)
      else:
        li.append(1)
  for i in range(len(li)-1):
    k=1
    for l in range(li[i+1]):
      k = k*li[i]
      if k > 998244353:
        k = k%998244353
    ans = (ans*(k%998244353)%998244353)
  print(ans)

Submission status: Wrong Answer

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

n = int(input())
dd = list(map(int, input().split()))
dd.sort()
ans = 1

for i in range(n):
    if dd[i] <= i:
        cnt = dd[:i].count(max(dd[:i+1])-1)
        ans *= max(cnt, 1)
    else:
        print(0)
        exit()

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def comb(y, x):
    if y // 2 < x:
        x = y - x
    t = 1
    for i in range(1, x + 1):
        t = t * (y + 1 - i) // i
    return t
mod = 998244353
def solve():
    n = int(input())
    D = Counter(map(int, input().split()))
    if 0 not in D:
        return 0
    max_d = max(D)
    if max_d == 1:
        return D[1]
    if max_d == 2:
        return D[1] * comb(D[1] + D[2] - 1, D[2] - 1)
    ans = D[1]
    for k in range(2, max(D) + 1):
        if k not in D:
            return 0
        v = D[k]
        last = D[k - 1]
        if last == 1:
            ans *= v
        elif v == 1:
            ans *= last
        else:
            ans += comb(last + v - 1, v - 1)
        ans %= mod
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
def cnt_figure(ls):
    figure = 1
    figure_cnt = 0
    ls_len = len(ls)
    re_fg_ls = []
    for i in range(ls_len):
        if figure == ls[i]:
            figure_cnt+=1
        else:
            re_fg_ls.append(figure_cnt)
            if figure == ls[i]-1:
                figure+=1
                figure_cnt=1
            else:
                figure_cnt = 0
                break
    re_fg_ls.append(figure_cnt)
    re_fg_ls.append(0)
    return re_fg_ls

n = int(input())
d_list = list(map(int, input().split()))
#print(d_list)
total = 0
now_figure = 0
if d_list[0] != 0:
    print(0)
else:
    d_list.pop(0)
    d_list.sort()
    #print(d_list)
    figure_ls = cnt_figure(d_list)
    #print(figure_ls)
    figure_ls_len = len(figure_ls)
    before_cnt = 1
    i = 0
    total = 1
    while figure_ls[i] != 0:
         total = total *(before_cnt**figure_ls[i]) % 998244353
         #print(total,"total")
         before_cnt = figure_ls[i]
         i+=1
    print(total % 998244353)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

const = 998244353

m = max(d)

a = d.count(0)

if a == 0:
    print(0)
else:
    ans = a

    new = ans

    for i in range(m):
        j = i + 1
        old = new
        new = d.count(j)
        if new == 0:
            ans = 0
            break
        else:
            ans = ans * pow(old, new)

    print(ans % const)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
R = max(D)
MOD = 998244353

cntD = Counter(D)
ans = 1
for i in range(1, R + 1):
    ans *= pow(cntD[i - 1], cntD[i], MOD)
    ans %= MOD

if cntD[0] == 0:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=1
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(1,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:
# -*- coding: utf-8 -*-
import collections

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

set_D = set(D)
c = collections.Counter(D)

sum = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
elif len(set_D)-1 == max(set_D):
  for i in range(len(set_D)):
    if i >= 1:
      sum *= c[i-1]**c[i]
  q, mod = divmod(sum, 99824435)
  print(mod)
else:
  print(0)

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(0)
cs = Counter(D)
count = 0
ans = 1
prev = 1
for i in range(N + 1):
    n = cs[i]
    if n == 0:
        if count == N:
            print(ans)
        else:
            print(0)
        exit(0)
    else:
        count += n
        ans = (ans * (prev ** n)) % 998244353
        prev = n

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(lambda x: int(x), input().split(' ')))

Es = [0 for i in range(100000)]

for d in Ds:
    Es[d] += 1

if Ds[0] != 0 or Es[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(Ds)-1):
        if Es[i] == 0:
            break
        ans *= (Es[i] ** Es[i+1]) % 998244353
    print(ans)

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):
    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]) % MOD
    ans *= tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def q1(n):
    return (n - 1) // 2


def q2(n, D):
    counts = np.array([np.sum(D == level) for level in range(n)])
    for i, c in enumerate(counts):
        if counts[i] == 0:
            if any(counts[i:] != 0):
                return 0
            counts = counts[:i]
            break
    return int(np.prod([n ** m for n, m in zip(counts[1:-1], counts[2:])]))
    # for i in range(2, n):
    #     if counts[i] == 0:
    #         return tmp
    #     tmp *= counts[i - 1] ** counts[i]


if __name__ == '__main__':
    MAXINT = 998244353

    # A 問題
    # n = int(input())
    # print(q1(n))

    # B 問題
    n = int(input())
    D = np.asarray(list(map(int, input().split())))
    # n = 4
    # D = np.array([0, 1, 1, 2])
    # D = np.array([1, 1, 1, 1])
    # n = 7
    # D = np.array([0, 3, 2, 1, 2, 2, 1])
    print(q2(n, D) % MAXINT)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
E = [abs(i-D[0]) for i in D[1:]]
d = dict(Counter(sorted(E)))
sum_=1
temp=1
i_temp = 0
if len(d) ==1:
    print(0)
    sys.exit()
for i in d.keys():
    if i-i_temp !=1:
        print(i,i_temp)
        print(0)
        sys.exit()
    add = (temp ** d[i]) % lim
    sum_ = (sum_ * add) % lim
    temp = d[i]
    i_temp = i
print(sum_)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
dl=list(map(int,input().split()))
MOD=998244353
dist=[0]*n
for d in dl:
    dist[d]+=1
ans=1
flg=False
for i in range(1,n):
    if dist[i]>0:
        if flg:
            ans=0
            break
        else:
            ans*=dist[i-1]**dist[i]%MOD
    else:
        flg=True
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = [int(i) for i in input().split()]

if D[0] != 0:
    val = 0
else:
    tmp = 1
    for n in range(1, N):  #1からN-1
        count = D.count(n)
        tmp = tmp * (n**count)
    val = tmp % 998244353
print(val)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ansflag = 0
ans = 1
for i in range(len(D_)):
    temp = D_[i]
    if temp == 0:
        ansflag = 1
        break
    else:
        if  i > 0:
            ans *= D_[i-1] ** D_[i]
            ans %= 998244353

if ansflag:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 2019/11/9

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

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

res={}
for e in d:
    res[e]=res.get(e,0)+1


def cmb(n,r,mod=10**9+7):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i%mod)
    ret=fac[n]*pow(fac[r]*fac[n-r]%mod,mod-2,mod)%mod
    return ret


ans=1
pre=res.get(1,-1)
if pre==-1:
    print(0)
    exit()

cnt=0
for i in range(2,len(res)):
    tmp=res.get(i,-1)
    if tmp==-1:
        print(0)
        exit()
    j=1
    while j<tmp:
        cnt+=cmb(tmp,j)
        j+=1
    cnt+=pre
    ans*=cnt%mod
    cnt=0
    pre=tmp
print(ans)

Submission status: Wrong Answer

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

counter = list(map( (lambda x: 0), range(N) ))

for distance in Ds:
    counter[ distance ] += 1   

if N == 1:
    if counter[0] == 1:
        result = 1
    else:
        result = 0
else:
    if counter[0] != 1 :
        result = 0
    else:
        result = 1

if N > 2:
    for distance in range(2,N):
        temp = pow( counter[distance-1], counter[distance] ) % 998244353
        result = (result * temp) % 998244353
         
print(result)

Submission status: Wrong Answer

Solution code:
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
a.sort()
num = a[-1]
aset = [0 for i in range(num+1)]

for i in a:
  aset[i] += 1
#print(aset)
if aset[0] == 1:
  ans = 1
  for i in range(1,num+1):
    ans = (ans * (aset[i-1]**aset[i] %mod )) %mod
    #print(aset[i-1], aset[i])
  print(ans)

else:
  print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np


def q1(n):
    return (n - 1) // 2


def q2(n, D):
    counts = np.array([np.sum(D == level) for level in range(n)])
    for i, c in enumerate(counts):
        if counts[i] == 0:
            if any(counts[i:] != 0):
                return 0
            counts = counts[:i]
            break
    return int(np.prod([n ** m for n, m in zip(counts[1:-1], counts[2:])]))
    # for i in range(2, n):
    #     if counts[i] == 0:
    #         return tmp
    #     tmp *= counts[i - 1] ** counts[i]


if __name__ == '__main__':
    MAXINT = 998244353

    # A 問題
    # n = int(input())
    # print(q1(n))

    # B 問題
    # n = int(input())
    # D = np.asarray(list(map(int, input().split())))
    n = 4
    # D = np.array([0, 1, 1, 2])
    # D = np.array([1, 1, 1, 1])
    n = 7
    D = np.array([0, 3, 2, 1, 2, 2, 1])
    print(q2(n, D) % MAXINT)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
m=l1[-1]
if l1[0]!=0:
  print(0)
else:
  ld=[0 for i in range(m+1)]
  b=False
  for i in range(n):
    ld[l[i]]+=1
  for i in range(1+m):
    if ld[i]==0:
      b=True
  if ld[0]!=1:
    print(0)
  elif b:
    print(0)
  else:
    ans=1
    for i in range(1,m+1):
      ans=(ans*((ld[i-1])**(ld[i])))%(998244353)
    print(ans%(998244353))

Submission status: Wrong Answer

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

MOD = 998244353

occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
for i in range(1, N+5):
    for j in range(occ[i]):
        cur = (cur * occ[i - 1]) % MOD

print(cur % MOD)

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = d[0]
max_d = d[-1]
mod = 998244353

if d[0] == d[1] or d[0] != 0:
    print(0)
    sys.exit()
count = [0 for _ in range(max_d-min_d+1)]
num = min_d
counter = 0
for i in range(n):
    if d[i] == num:
        counter += 1
    else:
        if d[i] == num+1:
            count[num-min_d] = counter
            counter = 1
            num += 1
        else:
            print(0)
            sys.exit()
count[-1] = counter
ans = count[1]
for i in range(1,max_d-min_d):
    n = count[i]-1
    m = count[i+1]
    ans *= (math.factorial(n+m)//(math.factorial(n)*math.factorial(m)))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

cnt = collections.Counter(D)
if D[0] != 0:
    ans = 0
else:
    ans = 1
    for i in range(1, max(D)+1):
        if cnt[i] == 0:
            ans *= 0
            break
        else:
            ans *= i ** cnt[i]

print(ans%998244353)

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(1,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:
N = int(input())
D = list(map(int, input().split()))

D.sort()
ans = 1
distance = 0
prev = 1
now = 0
for i in range(len(D)):
    if D[i] == distance:
        now += 1
    elif D[i] == distance + 1:
        ans = ans * prev ** now
        prev = now+0
        now = 1
        distance += 1
    else:
        ans = 0
        break
else:
    ans = ans * prev ** now

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
for i in range(1,N):
  ans = ans*pow(D.count(i-1),D.count(i))
print(int(ans%998244353))

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(lambda x: int(x), input().split(' ')))

Es = [0 for i in range(100000)]

for d in Ds:
    Es[d] += 1

if Ds[0] != 0 or Es[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(Ds)-1):
        if Es[i] == 0:
            break
        ans *= Es[i] ** Es[i+1]
    print(ans % 998244353)

Submission status: Wrong Answer

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

boxes = [[] for i in range(N)]
impossible = False
for idx,num in enumerate(ls):
    if num>=N:
        impossible=True
        break
    boxes[num].append(idx)

check_start=-1
ans = 1

if impossible:
    ans = 0
elif len(boxes[0])>=2:
    ans = 0
else:
    for i in range(N-1):
        a = len(boxes[i])
        b = len(boxes[i+1])
        if a == 0:
            check_start = i
            rest_ls = boxes[i:]
            if rest_ls.count([])!=len(rest_ls):
                ans = 0
            break
        ans*=a**b
baisu = ans//998244353
print(ans-(998244353*baisu))

Submission status: Wrong Answer

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

def pow_r(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2)
c = 0
if D[0] != 1:
    c += 1
    for i in range(1,max(D)):
        a = D.count(i)
        b = D.count(i+1)
        c *= pow_r(a,b)
print(c%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def comb(y, x):
    if y // 2 < x:
        x = y - x
    t = 1
    for i in range(1, x + 1):
        t = t * (y + 1 - i) // i
    return t
mod = 998244353
def solve():
    n = int(input())
    D = Counter(map(int, input().split()))
    if 0 not in D:
        return 0
    max_d = max(D)
    if max_d == 1:
        return D[1]
    if max_d == 2:
        return D[1] * comb(D[1] + D[2] - 1, D[2] - 1)
    ans = 1
    for k in range(1, max_d + 1):
        if k not in D:
            return 0
        v = D[k]
        last = D[k - 1]
        if last == 1:
            ans *= v
        elif v == 1:
            ans *= last
        else:
            ans += comb(last + v - 1, v - 1)
        ans %= mod
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    D = [int(c) for c in input().split()]

    if D[0] != 0:
        print(0)
        sys.exit()
    D.sort()
    for i in range(1, N):
        if D[i] >= N or D[i] == 0:
            print(0)
            sys.exit()
    list_ = [0 for i in range(N)]
    for i in range(N):
            list_[D[i]] += 1
    flag = True
    for i in range(N):
        if list_[i] == 0:
            flag = False
        if not flag and list_[i] != 0:
            print(0)
            sys.exit()
    ans = 1
    num = 1
    for i in range(1, N):
        if list_[i] == 0:
            break
        ans *= list_[i - 1] ** list_[i]
    print(ans)    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

if D[0]!=0:
    print(0)
else:
    count_list = [ np.where(D==x,1,0).sum() for x in range(1,D.max()+1)]
    
    if 0 in count_list:
        print(0)
        
    ans = 1
    for x in range(len(count_list)-1):
        ans = (ans * (count_list[x]**count_list[x+1]))%998244353
        if ans == 0:
            print(0)
            sys.exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int,input().split()))
if not D[0] == 0:
    print("0")
else:
    count = []
    ans = []
    for i in range(1,max(D)+1):
        node = D.count(i)
        ans.append(i**node)
    ans = np.prod(ans, axis = 0)
    print(ans)

Submission status: Wrong Answer

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

ans = 1
if d[0] != 0 and sum(d) < n - 2 and sum(d) > (n * (n - 1) // 2) + 1:
    print(0)
else:
    l = [0] * (max(d) + 1)
    for i in range(n):
        l[d[i]] += 1

    if l[0] != 1:
        print(0)
    else:
        for j in range(1, len(l)):
            if l[j] == 0:
                ans = 0
                break
            else:
                x = l[j - 1] ** l[j] % mod
                ans *= x
                ans %= mod
        print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
kaizyo = [1, 1]
for i in range(2, 100005):
    kaizyo.append(kaizyo[-1]*i % mod)

# print(kaizyo[:10])


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

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

prime_D = set(D)
prime_D = list(prime_D)
counter = {}

for i in range(len(prime_D)):
    counter[prime_D[i]] = 0

for i in range(len(D)):
    counter[D[i]] += 1  # 数を数えた

counter = sorted(counter.items(), key=lambda x: x[0])

if counter[0][1] > 1:
    print(0)  # 1との距離が0のものがあったらアウト
    exit()

# 距離が2離れているものは定義できない
now = counter[0][0]
for i in range(1, len(counter)):
    if counter[i][0] != (now+1):
        print(0)
        exit()
    now = counter[i][0]

# これですべての例外は弾けた
ans = 1
for i in range(len(counter)):
    ans *= (kaizyo[counter[i][1]] % mod)
    # if counter[i][1] == 1 and counter[i][0] != 0:
    #     ans *= ((counter[i][0]-1) % mod)

# print(counter)
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

mod = 998244353
from collections import Counter

def main():
  n = ni()
  d = na()

  if d[0] != 0:
    print(0)
    return
  
  pre = 0
  for dd in set(d[1:]):
    if dd - pre > 1:
      print(0)
      return
    pre = dd

  dic = {}
  for dd in d:
    if dd in dic:
      dic[dd] += 1
    else:
      dic[dd] = 1

  ans = 1
  t = sorted(dic.items(), key = lambda x: x[0])
  for i in range(1, len(t) - 1):
    x = (t[i][1] ** t[i+1][1]) % mod
    ans *= x
    ans %= mod
  print(ans % mod)
 

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int , input().split()))
max_d = 0
cnt = [0] * 10**5
for i in d:
    cnt[i] += 1
    max_d = max(i, max_d)
#print(cnt[:max_d+1])
#print(max_d)
if cnt[0] == 0:
    ans = 0
else:
    ans = 1
    for i in range(1, max_d + 1):
        if cnt[i] == 0:
            ans = 0
            break
        ans *= cnt[i-1] ** cnt[i] % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
# B - Counting of Trees
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

ans = 1
if D[0] > 0:
    print(0)
    exit()
else:
    for i in range(1,len(D)):
        ans *= D[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
D=list(map(int,input().split()))
if D[0]==0:
  A=collections.Counter(D)
  c=1
  for i in range(max(D)):
    c*=A[i]**A[i+1]
  ans=c%998244353  
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n = int(input())
D = [int(i) for i in input().split()]

if D[0] == 1:
    print(0)
    exit()
else:
    count = [0] * (len(D)+1)
    flag = [0] * (len(D)+1)
    for d in D:
        count[d] += 1
        flag[d] = 1

    ans = 1
    for i in range(1,sum(flag)):
        if count[i] <= 0:
            print(0)
            exit()
        else:
            ans *= i ** count[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
d = list( map(int, input().split()) )
MOD = 998244353

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0
    for i in range(2, iter+1):
        if c[i] == 0:
            return 0

    res = 1
    for i in range(2, iter+1):
        res *= c[i-1]**c[i] % MOD
    return res % MOD
res = count(c, max(d))
print(res)

Submission status: Wrong Answer

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

if d[0] != 0:
    print(0)
else:
    l = []
    ans = 1
    for i in range(n):
        c = d.count(i)
        l.append(c)
        if i == 0 and c != 1:
            ans = 0
            break
        if c != 0 and l[i-1] == 0:
            ans = 0
            break
        if i != 0:
            ans = ans * l[i-1] ** c
    print(ans%wari)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
a = sorted(d)
checkZero = False
if(d[0] != 0):
    checkZero = True
for i in range(1,len(d)):
    if(d[i] == 0):
        checkZero = True

if(checkZero):
    print(0)
else:
    start = 0
    counta = 0
    countb = 1
    ans = 1
    for i in a:
        if(start == i):
            counta += 1
        elif(start - i > 1):
            ans = 0
        else:
            ans *= countb ** counta
            start = i
            countb = counta
            counta = 1
    ans *= countb ** counta
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
D = list(map(int, input().strip().split(" ")))
d = list(set(D))

if min(d) > 0 or max(d) >= len(d):
    print(0)
    exit()

c = 1
x = [0] * len(d)
for i in D:
    x[i] += 1
if x[0] != 1:
    print(0)
    exit()
for i in range(1,len(d)):
    c *= x[i-1]**x[i]

print(c % 998244353)

Submission status: Wrong Answer

Solution code:

N = int(input())

D = [int(a) for a in input().split() ]

if D[0] != 0 or D.count(0) !=1:
    print("0")
    exit()


#calc
result = 1
x = D.count(1)
for i in range(2,N):
    y = D.count(i)
    if y!= 0:
        result = result * pow(x,y)
        x = y
print(result)

Submission status: Wrong Answer

Solution code:
def f():
    n = int(input())
    d = [int(s) for s in input().split()]
    d.sort()
    if d[0] != 0:
        return 0
    if len(d)==1:
        return 1
    if d[1] != 1:
        return 0
    count = [1]
    v = 0
    c = 1
    for i in range(1,n):
        if d[i] == v:
            c += 1
        else:
            if d[i] != (v+1):
                return 0
            count.append(c)
            v += 1
            c = 1
    count.append(c)

    ans = 1
    last = 1
    for cur in count:
        ans *= (last**cur)%998244353
        last = cur
    return ans % 998244353

print(f())

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0]*N
for D in Ds:
    counter[D] += 1
total = 0
cnt = 0
prenumi = 0
for i in range(N):
    if i == 0:
        if counter[i] == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = counter[i]
        if numi != 0:
            total = (total % CONST_DIVSOR) * (prenumi ** numi)
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break

print(total % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
import collections
import sys
sys.setrecursionlimit(100000)
nCr = {}


def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


def main():
    n = int(input())
    d_list = list(map(int, input().split()))
    d_list.sort()
    d_max = max(d_list)

    d_col = collections.Counter(d_list)
    if d_col.get(0, 0) == 0:
        print(0)
        return
    else:
        ans = 1
        for i in range(d_max, 0, -1):
            d_col_i = d_col.get(i, 0)
            temp_cmb = 0
            for j in range(d_col_i, (d_col_i // 2), -1):
                temp = cmb(d_col_i, j)
                temp_cmb += temp
            temp_ans = d_col.get(i - 1, 0) * temp_cmb
            ans *= temp_ans
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

d_max=max(d)
ans=1
flag=True

if d[0]!=0:
    print(0)
elif d.count(0)>1:
    print(0)
elif d_max==1:
    print(d.count(1))
else:
    for i in range(2, d_max+1):
        if d.count(i-1)==0 or d.count(i)==0:
            flag=False
            break
        else:
            ans*=(d.count(i-1)**d.count(i))%998244353
    print(ans%998244353 if flag else 0)

Submission status: Wrong Answer

Solution code:
import numpy as np
input1 = list(map(int,input().split()))
input2 = list(map(int,input().split()))

N = input1[0]
D = input2

counter = []

for num in range(max(D)+1):
  counter.append(D.count(num))

ans = 1

if counter[0] != 1:
  ans = 0
else:
  for i in range(len(counter)-1):
    ans *= counter[i]**counter[i+1]
    if ans >= 998244353:
      ans = ans%998244353


print(ans)

Submission status: Wrong Answer

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

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

count_dict = sorted(Counter(D).items(), key=lambda x:x[0])
count_list = list(dict(count_dict).values())

if not 0 in D[1:]:
    ans = 1
    for i in range(len(count_list)):
        if i == 0:
            if D[0] == 0:
                pass
            else:
                ans = 0
                break
        else:
            ans *= power_func(count_list[i - 1], count_list[i], p)
else:
    ans = 0

ans %= p
print(ans)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d.count(0) != 1:
        print(0)
    else:
        count = 1
        for i in d[1:][::-1]:
            if i <= 1:
                break
            count = ((count % mod) * (i % mod)) % mod
        print(count % mod)


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 *= pow(ans[i-1],ans[i],MOD)
    ret %= MOD
if ans[0] == 1:
    print(ret)
else:
    print(0)