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: Accepted

Solution code:

# mを法とするときのa^n
def modpow(a,n,m):
    res = 1
    t = a
    while n:
        if n%2:
            res = (res*t)%m
        t = (t*t)%m
        n //= 2
    return res

MOD = 998244353

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

if D[0] != 0 or any(d == 0 for d in D[1:]):
    print(0)
    exit()

memo = [0]*(max(D)+1)
for d in D:
    memo[d] += 1



cnt = 1
for a,b in zip(memo, memo[1:]):
    cnt *= modpow(a,b,MOD)
    cnt %= MOD

print(cnt)

Submission status: Accepted

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

if d[0] != 0:
    ans = 0
else:
    d.sort()
    d.append(d[-1] + 1)
    if d[1] == 0:
        ans = 0
    else:
        x = 1
        cnt_prev = 1
        cnt = 0
        ans = 1
        for i in range(1, n + 1):
            if d[i] == x:
                cnt += 1
            elif d[i] == x + 1:
                # print(x, cnt, cnt_prev)
                ans *= cnt_prev**cnt
                ans %= MOD
                cnt_prev = cnt
                cnt = 1
                x += 1
            else:
                ans = 0
                break

print(ans)

Submission status: Accepted

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

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

ans = 1
for i in range(len(ctr)-1):
    ans *= pow(ctr[i], ctr[i+1], MOD)
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


DIV = 998244353

def main():
    N = iRaw()
    Ds = isRaw()
    if Ds[0]!=0:
        return 0
    has_n = [0]*(N+1)
    has_n[0] = 1
    Ds = Ds[1:]
    Ds.sort()
    ans = 1
    for d in Ds:
        if d == 0:
            return 0
        else:
            if has_n[d-1]==0:
                return 0
            else:
                has_n[d]+=1
                ans = (ans*has_n[d-1])%DIV
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
from operator import itemgetter
from itertools import groupby
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0]!=0:
    print(0)
    exit()
ID = sorted(enumerate(D[1:]), key=itemgetter(1))
ans = 1
pn = 1

for i, (v, g) in enumerate(groupby(ID, key=itemgetter(1)), 1):
    if i != v:
        ans = 0
    n = len(list(g))
    ans = (ans * pow(pn, n, mod)) % mod
    pn = n

print(ans)

Submission status: Accepted

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

mod=998244353
if d[0]!=0:
    print(0)
    exit()
if 0 in d[1:]:
    print(0)
    exit()

ans=1
from collections import Counter
c=Counter(d)

for i in range(1,max(d)+1):
    if not i in c:
        print(0)
        exit()
    ans*=(c[i-1]**c[i])
    ans%=mod

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    md = 998244353
    n = int(input())
    dd = list(map(int, input().split()))
    if dd[0] > 0:
        print(0)
        exit()
    cnt = [0] * n
    for d in dd[1:]:
        if d == 0:
            print(0)
            exit()
        cnt[d] += 1
    ans = 1
    pc = 1
    for c in cnt[1:]:
        ans *= pow(pc, c, md)
        ans %= md
        pc = c
    print(ans)

main()

Submission status: Accepted

Solution code:
from collections import Counter
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0 or 0 in d[1:]:
    print(0)
    exit(0)
c = [0] * n
for x in d:
    c[x] += 1
t = 1
ans = 1
for i in range(n - 1):
    ans *= pow(t, c[i], MOD)
    t = c[i]
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
mod = 998244353

n = int(input())
ds = list(map(int, input().split()))
if ds[0] != 0:
    print(0)
    exit(0)
ds = ds[1:]
dd = defaultdict(int)
dmax = -1
for d in ds:
    if d <= 0:
        print(0)
        exit(0)
    dd[d] += 1
    dmax = max(d, dmax)

for d in range(1, dmax+1):
    if d not in dd:
        print(0)
        exit(0)

total = 1
dd[0] = 1
for d in range(1, dmax+1):
    total *= (dd[d-1] ** dd[d])
    total = total % mod
print(total)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 998244353

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
D = III()

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

count = [0]*(N+1)
for i in range(N):
    count[D[i]] += 1

if count[0]>=2:
    print(0)
    exit()

for i in range(N+1)[::-1]:
    if count[-1]==0:
        count.pop()
    else:
        break

ans = 1
for i in range(1,len(count)):
    ans *= count[i-1]**count[i]
    ans %= mod

print(ans)

Submission status: Accepted

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

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

dist2 = sorted(dist[1:])
dist2.append(-1)
idx = 0
ans = 1
before = 1

for now in range(1, n):
	count = 0
	if dist2[idx] == -1:
		break
	if dist2[idx] != now:
		print(0)
		exit()
	while dist2[idx] == now:
		idx += 1
		count += 1

	ans *= (before ** count)
	ans %= mod
	before = count

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
D=[int(i) for i in input().split()]
mod=998244353
import collections
DD=collections.Counter(D)
d=max(D)
ans=1
if D[0]!=0:
  print(0)
else:
  if DD[0]>1:
    ans=0
  else:
    for i in range(1,d+1):
      if DD[i]==0:
        ans=0
      else:
        ans=(ans*(DD[i-1]**DD[i]))%mod
  print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=998244353
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    C=[0]*100001
    D=list(map(int,input().split()))
    if(D[0]!=0):
        print(0)
        return
    for d in D:
        C[d]+=1
    if(C[0]!=1):
        print(0)
        return
    for i in range(100000):
        if(C[i]==0 and C[i+1]!=0):
            print(0)
            return
    i=C.index(0)
    C=C[:i]
    ans=1
    for i in range(1,len(C)):
        ans*=C[i-1]**C[i]
        ans%=MOD
    print(ans)
resolve()

Submission status: Accepted

Solution code:
def main():
    mod=998244353
    n=int(input())
    d = list(map(int,input().split())) 
    if d[0]!=0:
        print(0)
        return
    cnt=[0 for _ in range(n-1)]
    for i in range(n-1):
        cnt[d[i+1]-1]+=1
    for i in range(len(cnt)):
        if cnt[len(cnt)-1-i]!=0:
            maxd=len(cnt)-i
            break
    ans=1
    for i in range(maxd-1):
        x=cnt[i]
        for _ in range(cnt[i+1]-1):
            x=(x*cnt[i])%mod
        ans=(ans*x)%mod

    print(ans)    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
D = [int(d) for d in input().split()]
length = dict()
maxD = max(D)
mod = 998244353
for i in range(maxD + 1):
    length[i] = 0
for d in D:
    length[d] += 1
if D[0] != 0 or length[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(1, maxD + 1):
        if length[i] == 0:
            print(0)
            break
        else:
            ans *= (length[i-1] ** length[i]) % mod
            ans %= mod
    else:
        print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  if l[0]!=0 or l.count(0)!=1:
    return 0

  ans=1
  l.sort()
  a=[0]*100010
  a[0]=1
  for x in l[1:]:
    a[x]+=1
    ans*=a[x-1]
    ans%=998244353

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
import os
import sys
from collections import Counter

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

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

N = int(sys.stdin.readline())
D = list(map(int, sys.stdin.readline().split()))


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

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

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

Submission status: Accepted

Solution code:
mod = 998244353
n = int(input())
l = list(map(int, input().split()))
m = [0]*(max(l)+1)
for x in l:
    m[x] += 1
if l[0] != 0 or not all(l[1:]) or not all(m):
    print(0)
    exit()
t = 1
r = 1
for x in m:
    t = t * pow(r,x,mod) % mod
    r = x

print(t)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))
mod = 998244353
new = [0 for _ in range(max(d)+1)]
for x in d:
  new[x] += 1
if d[0] != 0:
  print(0)
elif new[0] != 1:
  print(0)
else:
  ans = 1
  for i in range(1,max(d)+1):
    ans *= new[i-1] ** new[i]
    #print(new[i],new[i-1],ans)
    ans %= mod
  print(ans)

Submission status: Accepted

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

mod = 998244353
di = defaultdict(int)
btr = 0
if d[0] != 0:
    print(0)
    exit()
for i in range(n):
    di[d[i]] += 1

keylist = sorted(list(di.keys()))
if di[0] != 1:
    print(0)
    exit()
result = 1
for i in range(1, len(keylist)):
    if i != keylist[i]:
        print(0)
        exit()
    result = result * (di[i-1] ** di[i]) % mod

print(result)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
d = list(map(int, input().split()))
max_d = max(d)
c = Counter(d)
mod = 998244353

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

if N == 1:
    if d[0] == 0:
        print(1)
    else:
        print(0)
    exit()

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

ans = 1
prev = 1
for i in range(1, max_d + 1):
    if c[i] == 0:
        ans = 0
    ans = (ans * pow(prev, c[i], mod)) % mod
    prev = c[i]

print(ans)

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline
con = 998244353

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	D = getlist()
	M = max(D)
	dic = defaultdict(int)
	for i in D:
		dic[i] += 1
	if D[0] != 0 or dic[0] >= 2:
		print(0)
	else:
		ans = 1
		for i in range(M):
			x = dic[i]
			y = dic[i + 1]
			for j in range(y):
				ans = ans * x
				ans %= con
		print(ans)
	
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n=int(input())
dlist=[int(i) for i in input().split()]
if dlist[0]!=0:
    print(0)
else:
    dlist=sorted(dlist)
    before=0
    kyolist=[0]
    dame=0
    for i in range(n):
        if dlist[i]==before:
            kyolist[-1]+=1
        elif dlist[i]==before+1:
            kyolist.append(1)
        else:
            dame=1
        before=dlist[i]
    #print(kyolist)
    if dame==1 or kyolist[0]!=1:
        print(0)
    else:
        if len(kyolist)<=2:
            print(1)
        else:
            answer=1
            for i in range(len(kyolist)-1):
                answer*=(kyolist[i]**kyolist[i+1])
            print(answer%998244353)

Submission status: Accepted

Solution code:
MOD = 998244353


def main():
    N = int(input())
    D = list(map(int, input().split()))
    M = max(D)
    cnt = [0] * (M+1)
    for x in D:
        cnt[x] += 1
    if D[0] != 0 or cnt[0] != 1:
        print(0)
        return
    for x in range(1, M+1):
        if cnt[x] == 0:
            print(0)
            return
    ans = 1
    for i in range(1, M):
        ans = (ans * pow(cnt[i], cnt[i+1], MOD)) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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
    if f[0] != 1:
        print(0)
        return
    if d[0] != 0:
        print(0)
        return
    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: Accepted

Solution code:
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] !=0:
    print(0)
else:
    cnt = [0]*N
    for i, d in enumerate(D):
        cnt[d]+=1
    cum = 1
    ans = 1
    for i in range(1, N):
        c = cnt[i]
        if c==0:
            break
        ans*=pow(cnt[i-1], c, mod)
        ans%=mod
        cum+=c
    if cum == N:
        print(ans)
    else:
        print(0)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
mod = 998244353
N = int(readline())
D = list(map(int, readline().split()))
cnt = [0]*(N+1)
for d in D:
    cnt[d] += 1

ans = 0
if cnt[0] != 1:
    ans = 0
elif D[0] != 0:
    ans = 0
elif len(set(D)) != 1 + max(D):
    ans = 0
else:
    ans = 1
    for i in range(1, N+1):
        dp = cnt[i-1]
        dn = cnt[i]
        if dn == 0:
            break
        ans = (ans*pow(dp, dn, mod)) %mod
print(ans)

Submission status: Accepted

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 or D[0]!=0:
    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: Accepted

Solution code:
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())


def solve():
    from collections import defaultdict
    import sys
    input = sys.stdin.readline
    mod = 998244353

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

    dic = defaultdict(int)
    for d_ in d[1:]:
        if d_ == 0:
            return 0
        dic[d_] += 1

    ans = 1
    pre_key = 0
    pre_value = 1
    for key, value in sorted(dic.items()):
        if key != pre_key + 1:
            return 0
        ans = ans * (pre_value ** value) % mod
        pre_key = key
        pre_value = value
    return ans


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

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

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

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

ans = 1
for i in range(1,n):
    ans*=pow(a[i-1],a[i],m)

print(ans%m)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    a = lmi()
    if a[0] != 0:
        exit(0)

    a.sort()
    ma = max(a)
    if a[1] == 0:
        exit(0)
    ans = 1
    dp = [0] * N
    for x in a:
        dp[x] += 1
    for i in range(1, ma + 1):
        ans = ans * pow(dp[i - 1], dp[i], 998244353) % 998244353
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    mod = 998244353
    N = int(input())
    D = list(map(int, input().split()))
    count = dict()
    for i in range(N):
        count[D[i]] = count.get(D[i], 0) + 1

    if D[0] != 0: return 0
    if 0 in D[1:]: return 0

    cnt = 1
    ans = 1
    prev = 1
    for i in range(1, N):
        if i in count:
            ans *= pow(prev, count[i]) % mod
            ans %= mod
            prev =  count[i]
            cnt += count[i]
            if cnt == N:
                return ans % mod
        else:
            return 0
    return 0


if __name__ == '__main__':
    # main()
    print(main())

Submission status: Accepted

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter


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

N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
	print(0)
	exit()


num_list = defaultdict(int)
max_num = max(D)
num_list[0] += 1

for i in range(1, N):
	if D[i] == 0:
		print(0)
		exit()
	num_list[D[i]] += 1

mod = 998244353
ans = 1
for i in range(max_num):
	ans *= pow(num_list[i], num_list[i + 1], mod)
	ans %= mod

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
MOD = 998244353

N = int(readline())
D = np.array(read().split(),np.int32)

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

counter = np.bincount(D,minlength=N)

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

arr = counter[D[1:] - 1]

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

answer = cumprod(arr,MOD)[-1]
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
B = C(A)

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

Submission status: Accepted

Solution code:
N = input()
D = map(int, raw_input().split())
if D[0]!=0 or N==1 or min(D[1:])==0:
  print 0
  exit(0)

D = D[1:]
D.sort()
C = [0]*N
C[0] = 1
ans = 1
for d in D:
  ans *= C[d-1]
  ans %= 998244353
  C[d] += 1
print ans

Submission status: Accepted

Solution code:
from collections import Counter


def solve(n, ddd):
    if ddd[0] != 0:
        return 0
    cnt = Counter(ddd)
    if cnt[0] != 1:
        return 0
    max_c = max(cnt)
    for i in range(max_c + 1):
        if i not in cnt:
            return 0

    MOD = 998244353
    ans = 1
    for i in range(max_c):
        prev = cnt[i]
        curr = cnt[i + 1]
        ans = ans * pow(prev, curr, MOD) % MOD
    return ans


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

print(solve(n, ddd))

Submission status: Runtime Error

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for item in d:
    if item[0]==1 or item[0]==0:
        continue
    if d[item[0]-1][1]==0:
        print(0)
        sys.exit()
    ans*=d[item[0]-1][1]**item[1]
    if ans>998244353:
        ans%=998244353
print(ans%998244353)

Submission status: Runtime Error

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for item in d:
    if item[0]==1 or item[0]==0:
        continue
    if item[1]==0:
        print(0)
        sys.exit()
    ans*=d[item[0]-1][1]**item[1]
    if ans>998244353:
        ans%=998244353
print(ans%998244353)

Submission status: Runtime Error

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for item in d:
    if item[0]==1 or item[0]==0:
        continue
    ans*=d[item[0]-1][1]**item[1]
    if ans>998244353:
        ans%=998244353
print(ans%998244353)

Submission status: Runtime Error

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for item in d:
    if item[0]==1 or item[0]==0:
        continue
    ans*=d[item[0]-1][1]**item[1]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for item in d:
    if item[0]==1 or item[0]==0:
        continue
    ans*=d[item[0]-1][1]**item[1]
print(ans)

Submission status: Runtime Error

Solution code:
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
if D[0]>0 or c[0]>1:print(0);exit()
a=1
for i in range(max(D)+1):a*=c[i]**c[i+1]
print(a)

Submission status: Runtime Error

Solution code:

def resolve():
    MOD = 998244353
    N = int(input())
    D = list(map(int, input().split()))

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

    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print(0)
        return

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

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    most_far = max(d)
    for i in range(most_far-1):
        ans *= d.count(most_far - (i+1))**d.count(most_far-i)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1,n):
        dp = d[i] - 1
        ans *= d.count(dp)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = {}
mod = 998244353
max_v = 0
lis = list(map(int, input().split()))

# 先頭はかならず0
if lis[0] != 0:
    print(0)
    exit()

for v in list(map(int, input().split())):
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)

# 0はひとつだけ
if 0 not in d or d[0] > 1:
    print(0)
    exit()

ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = {}
mod = 998244353
max_v = 0
for v in list(map(int, input().split())):
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)
# 0はひとつだけ
if d[0] > 1:
    print(0)
    exit()
ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys

n=int(input())

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

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

lis=[0 for i in range(n)]

for i in range(n):
    lis[d[i]]+=1

s=1

i=0
while lis[i+1]!=0:
    s=(s*pow(lis[i],lis[i+1],998244353))%998244353
    i+=1
print(s)

Submission status: Runtime Error

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

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

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for k in dic.keys():
        if k == 0:
            continue
        ans *= pow(dic[k-1], dic[k], 998244353)

    print(ans%998244353)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

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

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for k, v in dic.items():
        if k == 0:
            continue
        ans *= pow(dic[k-1], v, 998244353)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

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

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for k, v in dic.items():
        if k == 0:
            continue
        ans *= pow(dic[k-1], v)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
    cnt[d] += 1

if cnt[0] != 1:
    print(0)
    exit()
ans = cnt[0]
for i in range(1, dmax + 1):
    if cnt[i] == 0:
        print(0)
        exit()
    now = my_pow(cnt[i - 1], cnt[i], MOD)
    ans *= now
    ans %= MOD
print(ans)