提出 #8352078


ソースコード 拡げる

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>;

vector<mint> fact, factinv;
static void fact_reserve(int n)
{
    fact.resize(n + 1);
    factinv.resize(n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) {
        fact[i] = (ll)fact[i - 1] * i;
    }
    factinv[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) {
        factinv[i - 1] = (ll)factinv[i] * i;
    }
}

mint P(int n, int k) {
    return fact[n] * factinv[n-k];
}
mint C(int n, int k) {
    return fact[n] * factinv[n-k] * factinv[k];
}
mint H(int n, int k) {
    return C(n+k-1, k);
}

int main() {
    int n;
    cin >> n;
    fact_reserve(n);
    vector<int> a(n, 0);

    for (int i = 0; i < n; ++i) {
        int d;
        cin >> d;
        a[d]++;
    }

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

    mint ans = 1;
    int cnt = a[0];
    for (int i = 1; cnt < n; cnt += a[i], i++) {
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }

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

    return 0;
}

提出情報

提出日時
問題 B - Counting of Trees
ユーザ kibi62
言語 C++14 (GCC 5.4.1)
得点 0
コード長 3029 Byte
結果 WA
実行時間 31 ms
メモリ 2176 KB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 300
結果
AC × 3
AC × 23
WA × 4
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
in01.txt AC 29 ms 2048 KB
in02.txt AC 28 ms 2048 KB
in03.txt AC 28 ms 2048 KB
in04.txt AC 27 ms 2048 KB
in05.txt AC 27 ms 2048 KB
in06.txt AC 29 ms 2176 KB
in07.txt AC 30 ms 2176 KB
in08.txt WA 30 ms 2048 KB
in09.txt WA 28 ms 2048 KB
in10.txt AC 7 ms 640 KB
in11.txt AC 2 ms 384 KB
in12.txt WA 25 ms 2048 KB
in13.txt WA 3 ms 384 KB
in14.txt AC 31 ms 2176 KB
in15.txt AC 30 ms 2176 KB
in16.txt AC 24 ms 2176 KB
in17.txt AC 21 ms 2176 KB
in18.txt AC 18 ms 2176 KB
in19.txt AC 18 ms 2176 KB
in20.txt AC 30 ms 2176 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