Submission #8353839


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

template <typename T>
T powint(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return powint(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<998244353>;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (auto &e: d) cin >> e;

    if (d[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    int m = *max_element(d.begin(), d.end());
    vector<int> a(m+1, 0);
    for (int i = 0; i < n; ++i) {
        a[d[i]]++;
    }

    if (a[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    mint ans = 1;
    for (int i = 1; i <= m; i++) {
        ans *= powint<mint>(a[i-1], a[i]);
    }
    
    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task B - Counting of Trees
User kibi62
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2489 Byte
Status AC
Exec Time 30 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 27
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt
All sample01.txt, sample02.txt, sample03.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, sample01.txt, sample02.txt, sample03.txt
Case Name Status Exec Time Memory
in01.txt AC 28 ms 1024 KB
in02.txt AC 27 ms 896 KB
in03.txt AC 27 ms 896 KB
in04.txt AC 26 ms 768 KB
in05.txt AC 27 ms 768 KB
in06.txt AC 28 ms 768 KB
in07.txt AC 29 ms 896 KB
in08.txt AC 27 ms 896 KB
in09.txt AC 26 ms 768 KB
in10.txt AC 6 ms 384 KB
in11.txt AC 2 ms 256 KB
in12.txt AC 23 ms 640 KB
in13.txt AC 3 ms 256 KB
in14.txt AC 30 ms 1024 KB
in15.txt AC 29 ms 896 KB
in16.txt AC 22 ms 640 KB
in17.txt AC 19 ms 640 KB
in18.txt AC 17 ms 640 KB
in19.txt AC 17 ms 640 KB
in20.txt AC 28 ms 640 KB
in21.txt AC 1 ms 256 KB
sample01.txt AC 1 ms 256 KB
sample02.txt AC 1 ms 256 KB
sample03.txt AC 1 ms 256 KB