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:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    import math
    from collections import Counter
    cntr = sorted(Counter(D).items(), key=lambda x: x[0])
    imax = cntr[-1][0]
    if cntr[0][1] != 1:
        print(0)
        return
    ans = 1
    for i in range(1, imax+1):
        if cntr[i][0] != i:
            ans = 0
            break
        ans = ans * pow(cntr[i-1][1], cntr[i][1], div) % div
    print(ans)

nikkei19q_b()

Submission status: Wrong Answer

Solution code:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    from collections import Counter
    cntr = sorted(Counter(D).items(), key=lambda x: x[0])
    imax = cntr[-1][0]
    if cntr[0][1] != 1:
        print(0)
        return
    ans = 1
    for i in range(1, imax+1):
        if cntr[i][0] != i:
            ans = 0
            break
        ans = ans * (cntr[i-1][1] ** cntr[i][1]) % div
    print(ans)

nikkei19q_b()

Submission status: Wrong Answer

Solution code:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    from collections import Counter
    cntr = sorted(Counter(D).items(), key=lambda x: x[0])
    imax = cntr[-1][0]
    if cntr[0][1] != 1:
        print(0)
        return
    ans = 1
    for i in range(imax+1):
        if cntr[i][0] != i:
            ans = 0
            break
        ans = ans * (cntr[i-1][1] ** cntr[i][1]) % div
    print(ans)

nikkei19q_b()

Submission status: Wrong Answer

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

M = max(D)
cnt = [0 for i in range(M + 1)]

for d in D:
    cnt[d] += 1

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

res = 1
MOD = 998244353
for i in range(2, M + 1):
    res *= cnt[i - 1] ** cnt[i]
    res %= MOD

print(res)

Submission status: Wrong Answer

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

while N in D:
    continue

Submission status: Wrong Answer

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

M = max(D)
cnt = [0 for i in range(10**5+1)]

for d in D:
    cnt[d] += 1

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

for c in cnt[:M]:
    if c == 0:
        print(0)
        exit()

res = 1
MOD = 998244353
for i in range(2, M + 1):
    for c in range(cnt[i]):
        res = (res * cnt[i - 1]) % MOD

print(res)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int, input().split()))
d = collections.Counter(D)
maxnum = max(D)
ans = 1
for i in range(maxnum+1):
    if i == 0:
        if D[0] != 0 or d.get(0,0) != 1:
            ans = 0
            break
    else:
        if d.get(i, 0) == 0:
            ans = 0
            break
        ans *= d[i-1]**d[i]
print(ans)

Submission status: Wrong Answer

Solution code:
# import bisect
import unittest
from io import StringIO
# https://note.nkmk.me/python-scipy-connected-components/
from collections import Counter, deque
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        n = int(input())
        D = list(map(int, input().split()))
        cnts=[0]*(max(D)+1)
        for i in D:
            cnts[i]+=1

        
        ans=1
        if cnts[0]!=1: return 0
        for i in range(2,max(D)+1):
            if cnts[i]==0:
                return 0
            ans*=cnts[i-1]**cnts[i]

        return ans % 998244353

    print(main())

resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
import unittest
from io import StringIO
# https://note.nkmk.me/python-scipy-connected-components/
from collections import Counter, deque
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        n = int(input())
        D = list(map(int, input().split()))
        DD = Counter(D)
        from collections import OrderedDict
        DD = OrderedDict(sorted(DD.items(), key=lambda x: x[0]))
        cnts=[0]*n

        for k, v in DD.items():
            cnts[k]=v
        
        ans=1
        if cnts[0]!=1: return 0
        for i in range(2,max(D)+1):
            if cnts[i]==0:
                return 0
            ans*=cnts[i-1]**cnts[i]

        return ans % 998244353

    print(main())

resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
import unittest
from io import StringIO
# https://note.nkmk.me/python-scipy-connected-components/
from collections import Counter, deque
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        n = int(input())
        D = list(map(int, input().split()))
        DD = Counter(D)
        from collections import OrderedDict
        DD = OrderedDict(sorted(DD.items(), key=lambda x: x[0]))
        cnts=[0]*n

        for k, v in DD.items():
            cnts[k]=v
        
        ans=1
        if cnts[0]!=1: return 0
        for i in range(2,max(D)+1):
            ans*=cnts[i-1]**cnts[i]

        return ans % 998244353

    print(main())

# 
resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
import unittest
from io import StringIO
# https://note.nkmk.me/python-scipy-connected-components/
from collections import Counter, deque
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        k = int(input())
        D = list(map(int, input().split()))
        DD = Counter(D)
        from collections import OrderedDict
        DD = OrderedDict(sorted(DD.items(), key=lambda x: x[0]))
        ans = 1
        if (0, 1) not in DD.items():
            return 0
        temp = 1
        for k, v in DD.items():
            if k == 1:
                temp = v
            else:
                ans *= (temp**v)
                temp = v
        return ans % 998244353
    print(main())


# 
# 
resolve()

Submission status: Wrong Answer

Solution code:
# import bisect
import unittest
from io import StringIO
# https://note.nkmk.me/python-scipy-connected-components/
from collections import Counter, deque
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    def main():
        k = int(input())
        D = list(map(int, input().split()))
        DD = Counter(D)
        from collections import OrderedDict
        DD = OrderedDict(sorted(DD.items(), key=lambda x: x[0]))
        ans = 1
        if (0, 1) not in DD.items():
            return 0
        temp = 1
        for k, v in DD.items():
            ans *= (temp**v)
            temp = v
        return ans%998244353
    print(main())


resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
	def main():
		k=int(input())
		D=list(map(int,input().split()))
		DD=Counter(D)
		from collections import OrderedDict
		DD = OrderedDict(sorted(DD.items(), key=lambda x: x[0]))
		ans=1
		if (0,1) not in DD.items():
			return 0
		temp=1
		for k,v in DD.items():
			ans*=(temp**v)
			temp=v
		return ans
	print(main())

	

	
resolve()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    dd = MII()
    dd.sort()
    DIV = 998244353
    dist = {i: [] for i in range(max(dd)+1)}
    if dd[0] != 0:
        print(0)
        return None
    dist[0].append(1)
    for i,d in enumerate(dd[1:]):
        if d == 0:
            print(0)
            return None
        if dist[d-1]:
            dist[d].append(len(dist[d-1]))
    res = 1
    for d in dist.values():
        for di in d:
            res *= di
            res %= DIV
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    dd = MII()
    dd.sort()
    DIV = 998244353
    dist = {i: [] for i in range(max(dd)+1)}
    if dd[0] != 0:
        print(0)
        return None
    dist[0].append(1)
    for i,d in enumerate(dd[1:]):
        if d == 0:
            print(0)
            return None
        if dist[d-1]:
            dist[d].append(len(dist[d-1]))
    res = 1
    for d in dist.values():
        for di in d:
            res *= di
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
m = max(d)
if(d[0] != 0 or m >= n):
    print(0)
else:
    s = [0] * (m+1)
    for i in d:s[i] += 1
    if(0 in s or s[0] != 1):
        print(0)
    else:
        t = 1
        for i in range(1,m+1):
            t *= s[i-1]**s[i]
        print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

if __name__ == '__main__':
    MOD = 998244353
    n = int(input())
    d = list(map(int, input().split()))
    if d[0] != 0:
        print(0)
        exit(0)
    c = Counter(d)
    ans = 1
    for i in range(n - 1):
        ans *= pow(c[i], c[i + 1], MOD)
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

if __name__ == '__main__':
    MOD = 998244353
    n = int(input())
    d = list(map(int, input().split()))
    c = Counter(d)
    ans = 1
    for i in range(n - 1):
        ans *= pow(c[i], c[i + 1], MOD)
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()
d.sort()
if d[1] == 0:
    print(0)
    exit()
cnt = 1
pre = 1
ans =1
i = 0
mod = 998244353
while i < n:
    while i!=n-1 and d[i+1] == d[i]:
        i+=1
        cnt+=1
    ans *= pow(pre,cnt,mod)
    ans %= mod
    pre =cnt
    cnt = 1
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353

n = int(input())
dl = list(map(int, input().split()))
c = Counter(dl)

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

for x in range(max(dl)+1):
    if c[x]==0:
        print(0)
        exit()

res = 1
for x in range(max(dl)):
    res *= pow(c[x],c[x+1],mod)
    res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353

n = int(input())
dl = list(map(int, input().split()))
c = Counter(dl)

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

for x in range(max(dl)+1):
    if c[x]==0:
        print(0)
        exit()

res = 1
for x in range(max(dl)):
    res *= pow(c[x],c[x+1],mod)
    res %= mod

print(res)

Submission status: Wrong Answer

Solution code:
def pow(x,n):
    res = 1
    for _ in range(n):
        res *= x
    return max(1,res)

def main():
    N = int(input())
    lists = [0 for i in range(N+1)]
    temp = map(int,input().split())

    for elem in temp:
        lists[elem] += 1
    
    ans = 1


    if(lists[0] != 1):
        ans = 0
    else:
        sum = 1
        for i in range(1,N):
            ans *= pow(lists[i-1],lists[i])
            sum += lists[i]
            if(sum == N):
                break
                
            if(lists[i] == 0):
                if(sum != N):
                    ans = 0
                    break
                
    ans %= 998244353
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def pow(x,n):
    res = 1
    for _ in range(n):
        res *= x
    return max(1,res)

def main():
    N = int(input())
    lists = [0 for i in range(N+1)]
    temp = map(int,input().split())

    for elem in temp:
        lists[elem] += 1
    
    ans = 1


    if(lists[0] != 1):
        ans = 0
    else:
        sum = 1
        for i in range(1,N):
            ans *= pow(lists[i-1],lists[i])
            sum += lists[i]
            if(sum == N):
                break
    ans %= 998244353
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def pow(x,n):
    res = 1
    for _ in range(n):
        res *= x
    return max(1,res)

def main():
    N = int(input())
    lists = [0 for i in range(N+1)]
    temp = map(int,input().split())

    for elem in temp:
        lists[elem] += 1
    
    ans = 1


    if(lists[0] != 1):
        ans = 0
    else:
        for i in range(N):
            ans *= pow(lists[i-1],lists[i])
    ans %= 998244353
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def pow(x,n):
    res = 1
    for _ in range(n):
        res *= x
    return max(1,res)

def main():
    N = int(input())
    lists = [0 for i in range(N+1)]
    temp = map(int,input().split())

    for elem in temp:
        lists[elem] += 1
    
    ans = 1


    if(lists[0] != 1):
        ans = 0
    else:
        for i in range(N):
            ans *= pow(lists[i-1],lists[i])
    
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 1
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if item[0] == 0 and item[1] != 1:
        ans = 0
        break

    ans *= (count ** item[1]) % MOD
    count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if item[0] == 0 and item[1] != 1:
        ans = 0
        break
    else:
        ans *= (count ** item[1]) % MOD
    count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if item[0] == 0 and item[1] != 0:
        ans = 0
        break
    else:
        ans *= (count ** item[1]) % MOD
    count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if i == 0 and item[1] != 0:
        break
    else:
        ans *= (count ** item[1]) % MOD
    count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if i == 0:
        count = item[1]
    else:
        ans *= (count ** item[1]) % MOD
        count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    print("ans: {}".format(ans))
    print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if i == 0:
        count = item[1]
    else:
        ans *= (count ** item[1]) % MOD
        count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

counter = Counter(D)
# print("counter: {}".format(counter))

ans = 1
count = 0
for i, item in enumerate(sorted(counter.items(), key=lambda x: x[0])):
    # print("ans: {}".format(ans))
    # print("i: {}, item: {}".format(i, item))
    if i != item[0]:
        ans = 0
        break
    if i == 0:
        count = item[1]
    else:
        ans *= count ** item[1]
        count = item[1]
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]

def check():
    t = sorted(list(set(D)))
    if t == list(range(len(t))):
        return True
    return False


def main():
    if check() == False:
        print(0)
        return

    C = {}
    m = 0
    for d in D:
        C[d] = C.get(d,0) + 1
        m = max(m, d)

    if C[0] > 1:
        print(0)
        return

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

    print(ans % 998244353)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]

def check():
    t = sorted(list(set(D)))
    if t[0] == 0 and max(t)+1 == len(t):
        return True
    return False


def main():
    if check() == False:
        print(0)
        return

    C = {}
    m = 0
    for d in D:
        C[d] = C.get(d,0) + 1
        m = max(m, d)

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

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

    print(ans)

main()

Submission status: Wrong Answer

Solution code:

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

p = [0 for i in range(ma+1)]

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

if p[0] != 1:
    print(0)
    exit()
else:
    ans = 1
    for i in range(1,ma+1):
        ans *= (p[i-1]**p[i])%mod
        ans %= mod
    
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
mod=998244353
pre=0
c=[0]*n
for dd in d:
  c[dd]+=1
max_i=0
for cc in c:
  if cc>0:
    max_i+=1
for i in range(max_i):
  if i==0:
    if c[i]==1:
      pre=c[i]
      continue
    else:
      ans=0
      break
  if c[i]!=0:
    ans*=pre**c[i]
    pre=c[i]
    ans%=mod
  elif c[i]==0:
    ans=0
    break
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
mod=998244353
pre=0
c=[0]*n
for dd in d:
  c[dd]+=1
max_i=0
for cc in c:
  if cc>0:
    max_i+=1
for i in range(max_i):
  if i==0:
    if c[i]==1:
      pre=c[i]
      continue
    else:
      ans=0
      break
  if c[i]!=0:
    ans*=pow(pre,c[i],mod)
    pre=c[i]
    ans%=mod
  elif c[i]==0:
    ans=0
    break
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
mod=998244353
pre=0
c=[0]*n
for dd in d:
  c[dd]+=1
max_i=0
for cc in c:
  if cc>0:
    max_i+=1
for i in range(max_i):
  if i==0:
    if c[i]==1:
      pre=c[i]
      continue
    else:
      ans=0
      break
  if c[i]!=0:
    ans*=pow(pre,c[i],mod)
    pre=c[i]
    ans%=mod
  else:
    ans=0
    break
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
mod=998244353
pre=0
c=[0]*n
for dd in d:
  c[dd]+=1
max_i=0
for cc in c:
  if cc>0:
    max_i+=1
  else:
    break
for i in range(max_i):
  if i==0:
    if c[i]==1:
      pre=c[i]
      continue
    else:
      ans=0
      break
  if c[i]!=0:
    ans*=pow(pre,c[i],mod)
    pre=c[i]
    ans%=mod
  else:
    ans=0
    break
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
mod=998244353
pre=0
c=[0]*n
for dd in d:
  c[dd]+=1
max_i=0
for cc in c:
  if cc>0:max_i+=1
for i in range(max_i):
  if i==0:
    if c[i]==1:
      pre=c[i]
      continue
    else:
      ans=0
      break
  if c[i]!=0:
    ans*=pow(pre,c[i],mod)
    pre=c[i]
    ans%=mod
  else:
    ans=0
    break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 or Count[0]!=0:print(0);exit()

ans=1
for i in range(1,max(D)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if D[0]!=0 and Count[0]!=0:print(0);exit()

ans=1
for i in range(1,max(D)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)

Submission status: Wrong Answer

Solution code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C

from collections import Counter
n = int(input())
d = list(map(int,input().split()))
mod = 998244353

cnt = Counter(d)
len_cnt = len(cnt)
ans = 1

for i in range(len_cnt):
    #距離が飛んでる場合ダメ
    if cnt[i] == 0:
        ans = 0
        break
    #0は一つしかない
    if i == 0:
        if cnt[i] == 1:continue
        else:break

    if i == 1:ans = cnt[i]
    else:
        temp = pow(ans, cnt[i], mod)
        if i != len_cnt - 1:temp *= com(cnt[i + 1] + cnt[i] - 1, cnt[i] - 1, mod)
        ans = temp % mod
print(ans % mod)

Submission status: Wrong Answer

Solution code:
def com(n,r,mod):
    k=min(r,n-r)
    C=1
    for i in range(1,k+1):
        C=(C*(n+1-i)*pow(i,mod-2,mod))%mod
    return C

from collections import Counter
n = int(input())
d = list(map(int,input().split()))
mod = 998244353

cnt = Counter(d)
len_cnt = len(cnt)
ans = 1

for i in range(len_cnt):
    #距離が飛んでる場合ダメ
    if cnt[i] == 0:
        ans = 0
        break
    #0は一つしかない
    if i == 0:
        if cnt[i] == 1:continue
        else:break

    if i == 1:ans = cnt[i]
    else:
        temp = pow(ans, cnt[i], mod)
        if i != len_cnt - 1:temp *= com(cnt[i], cnt[i + 1], mod)
        ans = temp % mod
print(ans % mod)

Submission status: Wrong Answer

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

cnt = Counter(d)
len_cnt = len(cnt)
ans = 0

for i in range(len_cnt):
    #距離が飛んでる場合ダメ
    if cnt[i] == 0:
        ans = 0
        break
    #0は一つしかない
    if i == 0:
        if cnt[i] == 1:continue
        else:break

    if i == 1:ans = cnt[i]
    else:
        temp = pow(ans, cnt[i], mod)
        if i != len_cnt - 1:temp = (temp * cnt[i]) % mod
        ans = temp % mod
print(ans % mod)

Submission status: Wrong Answer

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

cnt = Counter(d)
#print(cnt)
len_cnt = len(cnt)
ans = 1

for i in range(len_cnt):
    #距離が飛んでる場合ダメ
    if cnt[i] == 0:
        ans = 0
        break
    #0は一つしかない
    if i == 0:
        if cnt[i] == 1:continue
        else:break

    else:
        temp = pow(ans, cnt[i], mod)
        if i != len_cnt - 1:temp *= cnt[i]
        ans = temp % mod
print(ans % mod)