Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

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

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
d=list(map(int,input().split()))
dd = collections.Counter(d)
if dd[0]!=1:
    print(0)
    exit()
count=1
for i in range(1,max(d)+1):
    count = (count*pow(dd[i-1],dd[i],99844353))%99844353
print(count%99844353)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    cnt = {}
    for item in map(int, input().strip().split()):
        cnt.setdefault(item, 0)
        cnt[item] += 1
    result = 1
    if cnt.get(0, 0) != 1:
        print("0")
        return
    for key in cnt:
        if key == 0:
            continue
        # every level node can connect to every parent node
        # therefore each level provides parent's count to the current count
        # different dispositions
        for _ in range(cnt[key]):
            result *= cnt.get(key - 1, 0)
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = 1
setD = list(set(d))
# setD.sort()

if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        
        # for _d in d:
        #         if _d != 0:
        #                 # print(_d - 1)
        #                 print(c[_d - 1])
        #                 # print("---------------")
        #                 ans *= c[_d - 1]

        for _d in setD:
                if _d != 0:
                        ans *= c[_d - 1] ** c[_d]

        print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)
 
if not ans_li[0] == 1:
    print(0)
    exit()

for i in range(max(ans_li)):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
x=sorted(d)
acount=1
count=1
sd=set(x)
sd=list(sd)
s=0

for i in range(1,n-1):
  if x[i]==x[i+1]:
    acount+=1
  elif x[i]!=x[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(x)>1 and x[-1]!=x[-2]:
  ans*=count
elif len(x)>1 and x[-1]==x[-2]:
  ans*=(count**acount)

  
for i in range(len(sd)-1):
  if sd[i]+1!=sd[i+1]:
    s=1
    
if s==0:
  if d[0]==0 and d[1]!=0:
    print(ans%998244353)
  else:
    print(0)
else:
  print(0)

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if L[0] == 0 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for i in range(1,nonzerolast+1) :
  ans *= (L[i-1]) ** (L[i])
  ans %= MOD

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if L[0] != 1 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for i in range(1,nonzerolast+1) :
  ans *= (L[i-1]) ** (L[i])
ans %= MOD

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(DCounter.items())[1:]:
        num *= (mae ** value)
        mae = value
    print(num % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(DCounter.items())[1:]:
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(DCounter.items()):
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)

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
checkLen = len(set(D))
if not checkLen == len(countl):
    print(0)
    sys.exit()
if not countl[0] == 1:
    print(0)
    sys.exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import math
def func(i, j, d):
    if i <= 1:
        return 1
    e = j
    b = int(math.log2(d)/math.log2(i))
    ret = 1
    while e > b:
        ret = ret*(i**b%d)
        e = e - b
    else:
        if e > 0:
            ret = ret*(i**e%d)
    return ret


def main():
    N = int(input())
    Ds = [int(d) for d in input().split()]

    Ds.sort()
    if Ds.count(0) != 1:
        print(0)
        return

    i = 1
    l = 1
    r = 1
    ans = 1
    divider = 998244353

    while i < N:
        cnt = 0
        while i < N and Ds[i] == l:
            cnt = cnt + 1
            i = i + 1
        if cnt == 0:
            print(0)
            return

        ans = ans*func(r, cnt, divider)%divider
        r = cnt
        l = l + 1
    
    print(ans)

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

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",main)

Submission status: Wrong Answer

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

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

cnt = {}
for d in D:
    if not d in cnt: cnt[d] = 1
    else: cnt[d] += 1

cnt = sorted(cnt.items())
ans = 1
for i in range(1,len(cnt)):
    ans *= cnt[i-1][1]**cnt[i][1]
    ans %= MOD
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()))

#
c = Counter(D)
# DP =[1]*max(c)
# c.most_common()
#print(c)
ans = 1
if D[0] > 0:
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()
else:
    for i in range(1,max(D)+1):
        ans *= i**c[i]
        ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

if D[0]!=0:
  print(0)
  exit()
cnt=1
for i in range(N-2):
  a=D.count(i+1)
  b=D.count(i+2)
  if b!=0:
    cnt *= (a**b)
print(cnt)

Submission status: Wrong Answer

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

#
c = Counter(D)
# DP =[1]*max(c)
# c.most_common()
print(c)
ans = 1
if D[0] > 0:
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()
else:
    for i in range(1,max(D)+1):
        ans *= i**c[i]
        ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)
 
if not ans_li[0] == 1:
    print(0)
    exit()

if n == 1:
    print(0)
    exit()

for i in range(max(ans_li)):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0 and not ans_li[i+1] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(d)==1:
  d.append(1)
li=[]
for i in range(len(d)):
  li.append(d.count(i))
  
result=1
for i in range(1,len(li)):
  if li[i-1]<=1:
    pass
  else:
    now_len=li[i]
    pre_len=li[i-1]
    result*=pre_len**now_len
print(result%998244353)

Submission status: Wrong Answer

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

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:
import sys
n=int(input())
a,b,c,d,i=list(map(int,input().split())),0,[],1,0
if a[0]!=0:
    print('0')
    sys.exit()
a.sort()
if a[1]==0:
    print('0')
    sys.exit()
while True:
    if a[i]==a[i+1]:
        b+=1
    else:
        c.append(b+1)
        b=0
    i+=1
    if i+1>=n:
        c.append(b+1)
        break
if len(c)-1!=max(a):
    print('0')
    sys.exit()
for i in range(len(c)-1):
    d*=c[i]**c[i+1]
print(d)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)
 
if not ans_li[0] == 1:
    print(0)
    exit()

for i in range(max(ans_li)):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0 and not ans_li[i+1] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0:
        continue
    else:
        ct *= b[i-1]**b[i]
if b[0] != 1 and a[0] != 0:
    print(0)
else:
    print(ct%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)
    else:
        count = 1
        now_count = 1
        for i in range(max(D)):
            next_count = sum(D == i+1)
            if next_count == 0:
                print(0)
                break
            count = count * (now_count ** next_count)
            now_count = next_count
        print(count % 998244353)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

if D[0]!=0:
    print(0)
else:
    D.sort()
    D_max = D[-1]
    a = 1
    count = 0
    l = collections.Counter(D)
    for i in range(D_max+1):
        if l[i] == 0:
            count += 1
            break
    if count == 1:
        print(0)
    else:
        for i in range(1,D_max + 1):
            a = a*(l[i-1]**l[i])
        print(a%998244353)

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if L[0] != 1 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for i in range(1,nonzerolast+1) :
  ans *= (L[i-1]) ** (L[i])
  ans %= MOD

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)
 
if not ans_li[0] == 1:
    print(0)
    exit()

for i in range(n-1):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0 and not ans_li[i+1] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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


    print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
DL=[]
ansL=[]

if D[0]!=0:
    print(0)
else:
    maxD=max(D)
    for i in range(maxD+1):
        DL.append(D.count(i))
    for i in range(len(DL)-1):
        ansL.append(DL[i]**DL[i+1])
    from operator import mul
    from functools import reduce
    print((reduce(mul, ansL)))

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0:
        continue
    else:
        ct *= b[i-1]**b[i]
if b[0] != 1 and any(b[i] for i in range(1,max(a))):
    print(0)
else:
    print(ct%998244353)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

if D[0]!=0:
    print(0)
else:
    D.sort()
    D_max = D[-1]
    a = 1
    l = collections.Counter(D)
    for i in range(D_max+1):
        if l[i] == 0:
            print(0)
            break
    for i in range(1,D_max + 1):
        a = a*(l[i-1]**l[i])
    print(a%998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if A[0] == 1 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for i in range(1,nonzerolast+1) :
  ans *= (L[i-1]) ** (L[i])
  ans %= MOD

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if A[0] == 1 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for i in range(1,nonzerolast+1) :
  ans *= (L[i-1]) ** (L[i])

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    if D[0] != 0:
        print(0)
        return
    
    ans = 1
    for i in range(len(C) -1):
        for _ in range(C[i+1]):
            ans *= C[i]
            ans %= 998244353
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
d.sort()
acount=1
count=1
sd=set(d)
sd=list(sd)
s=0

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(d)>1 and d[-1]!=d[-2]:
  ans*=count
elif len(d)>1 and d[-1]==d[-2]:
  ans*=(count**acount)

  
for i in range(len(sd)-1):
  if sd[i]+1!=sd[i+1]:
    s=1
if s==0:
  if len(d)>1 and d[0]==0 and d[1]!=0:
    print(ans%998244353)
  elif len(d)==1 and d[0]==0:
    print()
  elif d[0]!=0:
    print(0)
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

if D[0]!=0:
    print(0)
else:
    D.sort()
    D_max = D[-1]
    a = 1
    l = collections.Counter(D)
    for i in range(D_max+1):
        if l[i] == 0:
            print(0)
            break
    for i in range(1,D_max + 1):
        a = a*(l[i-1]**l[i])
    print(a)

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    Ds = [int(d) for d in input().split()]

    Ds.sort()
    if Ds.count(0) != 1:
        print(0)
        return

    i = 1
    l = 1
    r = 1
    ans = 1
    divider = 998244353

    while i < N:
        cnt = 0
        while i < N and Ds[i] == l:
            cnt = cnt + 1
            i = i + 1
        if cnt == 0:
            print(0)
            return
        ans = (ans*(r**cnt))%divider
        r = cnt
        l = l + 1
    
    print(ans)

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

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",main)

Submission status: Wrong Answer

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

ans = 1
# setD = list(set(d))
# setD.sort()
# nodeMulti = 1

if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        # for s in setD:
        #         ans *= math.factorial(c[s])
        #         nodeMulti *= c[s]
        # nodeMulti //= setD[-1]

        # for i in range(len(setD)-1):
                # ans *= (c[setD[i]] + c[setD[i+1]] - 1)
        
        # for _d in d:
        #         if _d != 0:
        #                 # print(_d - 1)
        #                 print(c[_d - 1])
        #                 # print("---------------")
        #                 ans *= c[_d - 1]

        # print(ans%998244353)

        hoge = 1
        for _d in d:
                if _d != 0:
                        hoge *= _d
        print(hoge)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
d = list(map(int, input().split()))
 
if d[0] != 0 and d[1] == 0:
    ans = 0
else:
    counter = Counter(d)
    ans = counter[0]
    for i in range(1, max(d) + 1):
        if counter[i] == 0:
            ans = 0
            break
        m, n = counter[i - 1], counter[i]
        c = m ** n
        ans *= c
        ans = ans%M
 
print(ans % M)

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(2/0)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(2/0)
		exit()
	else:
		print(0)
		exit()
from collections import Counter
q=Counter(d)
if q[0]!=1 or d[0]!=0:
	print(0)
	exit()
ans=1
for i in range(1,max(q)+1):
    ans *=pow(q[i-1],q[i],mod)
    ans %=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    d = sorted(d)
    if d[0] != 0:
        print(0)
        return
    
    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 in range(1, len(d)+1):
            
            ans *= tmp**count[i]
            #print(ans)
            tmp = count[i]


        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n = int(inputs[0])
D = list(map(int, inputs[1].split()))
MOD = 998244353
cnt = Counter(D)
if (D[0] != 0 or cnt[0] > 1):
    print(0)
else:
    ans = 1
    for i in range(1, max(D)+1):
        ans *= pow(cnt[i-1], cnt[i], MOD) % MOD
    print(ans)

Submission status: Wrong Answer

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

setD = list(set(d))
setD.sort()
ans = 1
# nodeMulti = 1

if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        # for s in setD:
        #         ans *= math.factorial(c[s])
        #         nodeMulti *= c[s]
        # nodeMulti //= setD[-1]

        # for i in range(len(setD)-1):
                # ans *= (c[setD[i]] + c[setD[i+1]] - 1)
        
        for _d in d:
                if _d != 0:
                        # print(_d - 1)
                        print(c[_d - 1])
                        # print("---------------")
                        ans *= c[_d - 1]

        # print(ans%998244353)

        hoge = 1
        for _d in d:
                if _d != 0:
                        hoge *= _d
        print(hoge)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    if C[0] != 1:
        print(0)
        return
    
    ans = 1
    for i in range(len(C) -1):
        for _ in range(C[i+1]):
            ans *= C[i]
            ans %= 998244353
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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()
from collections import Counter
q=Counter(d)
if q[0]!=1 or d[0]!=0:
	print(0)
	exit()
ans=1
for i in range(1,max(q)+1):
    ans *=pow(q[i-1],q[i],mod)
    ans %=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    if D[0] == 0:
        print(0)
        return
    
    ans = 1
    for i in range(len(C) -1):
        for _ in range(C[i+1]):
            ans *= C[i]
            ans %= 998244353
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for d in D:
        if d == 0 or d == 1:
            continue
        else:
            ans *= c[d-1]
            ans = int(ans) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()] 
if a[0]!=0 or a[n-1]==0: 
     print (0%998244353)
else:
    a = Counter(a)
    ans = 1
    for i in range(1,len(a)-1): 
        ans*=a[i]**a[i+1]
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        if tmp == cnt[i]:
            continue
        else:
            c = (tmp**cnt[i]) % mod
            ans *= c % mod
            tmp = cnt[i]
            ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

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

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

print(res % 998244353)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

if D[0]!=0:
    print(0)
else:
    D.sort()
    D_max = D[-1]
    count = 0
    a = 1
    for i in range(N-1):
        if D[i+1]-D[i] > 1: 
            count += 1
            break
    if count == 1:
        print(0)
    else:
        l = collections.Counter(D)
        for i in range(1,D_max + 1):
            a = a*(l[i-1]**l[i])
        print(a)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    if C[0] == 0:
        print(0)
        return
    
    ans = 1
    for i in range(len(C) -1):
        for _ in range(C[i+1]):
            ans *= C[i]
            ans %= 998244353
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()] 
if a[0]!=0: 
    print (0%998244353)
if a[n-1]==0:
     print (0%998244353)
else:
    a = Counter(a)
    ans = 1
    for i in range(1,len(a)-1): 
        ans*=a[i]**a[i+1]
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
d.sort()
acount=1
count=1
sd=set(d)
sd=list(sd)
s=0

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(d)>1 and d[-1]!=d[-2]:
  ans*=count
elif len(d)>1 and d[-1]==d[-2]:
  ans*=(count**acount)

  

if len(d)>1 and d[0]==0 and d[1]!=0:
  print(ans%998244353)
elif len(d)==1 and d[0]==0:
  print(1)
elif d[0]!=0:
  print(0)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    d = sorted(d)
    if d[0] != 0:
        print(0)
        return
    
    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 in range(1, len(items)+1):
            
            ans *= tmp**count[i]
            #print(ans)
            tmp = count[i]


        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
num_d=[0 for i in range(n)]
num_d[0]=1
if d[0]!=0:
  print(0)
  sys.exit()
for i in range(1,len(d)):
  if i==0:
    print(0)
    sys.exit()
  num_d[d[i]]+=1
max_d=0
ans=1
for i in range(1,n):
  if num_d[i]!=0:
    if max_d!=i-1:
      print(0)
      sys.exit()
    max_d=i
    ans*=num_d[i-1]**num_d[i]
    ans%=998244353
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

#根が2個あるならexit
if list2[0] != 1:
    print(0)
    exit()
#枝が繋がっていないならexit
if 0 in list2:
    print(0)
    exit()

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

print(count)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

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

D.sort()
D_max = D[-1]
count = 0
a = 1

if D[0]!=0:
    print(0)
else:
    for i in range(N-1):
        if D[i+1]-D[i] > 1: 
            count += 1
            break
    if count == 1:
        print(0)
    else:
        l = collections.Counter(D)
        for i in range(1,D_max + 1):
            a = a*(l[i-1]**l[i])
        print(a)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
num_d=[0 for i in range(n)]
if d[0]!=0:
  print(0)
  sys.exit()
for i in range(1,len(d)):
  if i==0:
    print(0)
    sys.exit()
  num_d[d[i]]+=1
max_d=0
ans=1
for i in range(1,n):
  if num_d[i]!=0:
    if max_d!=i-1:
      print(0)
      sys.exit()
    max_d=i
    ans*=num_d[i-1]**num_d[i]
    ans%=998244353
print(ans)