QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185117#6736. Alice and BobAyouziTL 0ms0kbC++142.2kb2023-09-21 17:20:322023-09-21 17:20:33

Judging History

你现在查看的是最新测评结果

  • [2023-09-21 17:20:33]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-09-21 17:20:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e7 + 10, Mod = 998244353;

int Norm(int x) {
    if (x < 0) x += Mod;
    if (x >= Mod) x -= Mod;
    return x;
}
template<class T>
T qmi(T a, ll b) {
    T res = 1;
    while (b) {
        if (b & 1) res *= a;
        b >>= 1;
        a *= a;
    }
    return res;
}
struct Z {
    int x;
    Z(int x = 0) : x(Norm(x)) {}
    Z(ll x) : x(Norm(x % Mod)) {}
    int val() const {
        return x;
    }
    Z operator-() const {
         return Z(Norm(Mod - x));
    }
    Z inv() const {
        assert(x != 0);
        return qmi(*this, Mod - 2);
    }
    Z &operator*=(const Z &rhs) {
        x = ll(x) * rhs.x % Mod;
        return *this;
    }
    Z &operator+=(const Z &rhs) {
        x = Norm(x + rhs.x);
        return *this;
    }
    Z &operator-=(const Z &rhs) {
        x = Norm(x - rhs.x);
        return *this;
    }
    Z &operator/=(const Z &rhs) {
        return *this *= rhs.inv();
    }
    friend Z operator*(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res *= rhs;
        return res;
    }
    friend Z operator+(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res += rhs;
        return res;
    }
    friend Z operator-(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res -= rhs;
        return res;
    }
    friend Z operator/(const Z &lhs, const Z &rhs) {
        Z res = lhs;
        res /= rhs;
        return res;
    }
    friend std::istream &operator>>(std::istream &is, Z &a) {
        ll v;
        is >> v;
        a = Z(v);
        return is;
    }
    friend std::ostream &operator<<(std::ostream &os, const Z &a) {
        return os << a.val();
    }
};
Z fact[N], infact[N];

void init() {
    fact[0] = infact[0] = 1;
    for (int i = 1; i < N; i ++ ) {
        fact[i] = fact[i - 1] * i;
        infact[i] = infact[i - 1] / i;  
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int n;
    cin >> n;
    Z ans = 0;
    for (int i = 1; n - i >= i - 1; i ++ ) {
        ans += fact[n - i] * fact[n - i] * infact[n - i - (i - 1)];
    }
    cout << ans << '\n';
    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:


result: