QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185117 | #6736. Alice and Bob | Ayouzi | TL | 0ms | 0kb | C++14 | 2.2kb | 2023-09-21 17:20:32 | 2023-09-21 17:20:33 |
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
1