Submission #35956221


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const int MOD = 998244353;

struct mint {
    int n;
    mint() : n(0) { ; }
    mint(ll m) {
        if (m < 0 || MOD <= m) {
            m %= MOD;

            if (m < 0)
                m += MOD;
        }

        n = m;
    }
    operator int() {
        return n;
    }
};
bool operator==(mint a, mint b) {
    return a.n == b.n;
}
mint operator+=(mint &a, mint b) {
    a.n += b.n;

    if (a.n >= MOD)
        a.n -= MOD;

    return a;
}
mint operator-=(mint &a, mint b) {
    a.n -= b.n;

    if (a.n < 0)
        a.n += MOD;

    return a;
}
mint operator*=(mint &a, mint b) {
    a.n = ((ll)a.n * b.n) % MOD;
    return a;
}
mint operator+(mint a, mint b) {
    return a += b;
}
mint operator-(mint a, mint b) {
    return a -= b;
}
mint operator*(mint a, mint b) {
    return a *= b;
}
template<typename T>
mint operator^(mint a, T n) {
    if (n == 0)
        return mint(1);

    mint res = (a * a) ^ (n / 2);

    if (n % 2)
        res = res * a;

    return res;
}
ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
mint operator/(mint a, mint b) {
    return a * mint(inv(b, MOD));
}
mint operator/=(mint &a, mint b) {
    a = a / b;
    return a;
}

vector<mint> fac, ifac;

void init(int n) {
    fac.resize(n + 1);
    ifac.resize(n + 1);
    fac[0] = ifac[0] = 1;

    for (int i = 1; i <= n; ++i)
        fac[i] = fac[i - 1] * mint(i);

    ifac[n] = mint(1) / fac[n];

    for (int i = n - 1; i >= 1; --i)
        ifac[i] = ifac[i + 1] * mint(i + 1);
}

mint C(int n, int m) {
    if (n < m || m < 0)
        return 0;

    assert(max(n, m) < fac.size());

    return fac[n] * ifac[m] * ifac[n - m];
}

mint A(int n, int m) {
    return fac[n] * ifac[n - m];
}

int main() {
    cin.tie(NULL)->ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(m), num(n + 1);

    init(n);

    for (int i = 1; i <= n; ++i) {
        ++cnt[i % m];
    }

    int mx = 0;

    for (int i = 0; i < m; ++i) {
        ++num[cnt[i]];

        if (cnt[i])
            mx = max(mx, cnt[i]);
    }

    auto ans = vector(n + 1, mint(0));

    for (int k = mx; k <= n; ++k) {
        mint res = 1;

        for (int j = 0; j <= n; ++j) {
            if (num[j]) {
                res *= A(k, j) ^ num[j];
            }
        }

        mint now = 1;

        for (int j = 0; j < k; ++j) {
            res -= ans[j] * now;
            now *= (k - j);
            //res -= ans[j] * A(k, k) / A(k - j, k - j);
        }

        res /= A(k, k);
        ans[k] = res;
    }

    for (int i = 1; i <= n; ++i)
        cout << ans[i] << "\n";

    return 0;
}

Submission Info

Submission Time
Task G - Groups
User SkqLiiiao
Language C++ (GCC 9.2.1)
Score 600
Code Size 2693 Byte
Status AC
Exec Time 85 ms
Memory 3748 KiB

Compile Error

In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from ./Main.cpp:1:
./Main.cpp: In function ‘mint C(int, int)’:
./Main.cpp:101:22: warning: comparison of integer expressions of different signedness: ‘const int’ and ‘std::vector<mint>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  101 |     assert(max(n, m) < fac.size());
      |            ~~~~~~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 38 ms 3668 KiB
random_02.txt AC 19 ms 3592 KiB
random_03.txt AC 46 ms 3676 KiB
random_04.txt AC 78 ms 3656 KiB
random_05.txt AC 73 ms 3604 KiB
random_06.txt AC 25 ms 3504 KiB
random_07.txt AC 12 ms 3600 KiB
random_08.txt AC 43 ms 3672 KiB
random_09.txt AC 59 ms 3652 KiB
random_10.txt AC 9 ms 3540 KiB
random_11.txt AC 7 ms 3576 KiB
random_12.txt AC 37 ms 3636 KiB
random_13.txt AC 2 ms 3568 KiB
random_14.txt AC 2 ms 3576 KiB
random_15.txt AC 2 ms 3644 KiB
random_16.txt AC 21 ms 3652 KiB
random_17.txt AC 31 ms 3512 KiB
random_18.txt AC 24 ms 3704 KiB
random_19.txt AC 60 ms 3540 KiB
random_20.txt AC 83 ms 3616 KiB
random_21.txt AC 85 ms 3748 KiB
random_22.txt AC 59 ms 3696 KiB
random_23.txt AC 83 ms 3716 KiB
random_24.txt AC 85 ms 3712 KiB
sample_01.txt AC 2 ms 3648 KiB
sample_02.txt AC 2 ms 3508 KiB
sample_03.txt AC 2 ms 3508 KiB