QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#412548 | #6736. Alice and Bob | XiaoretaW# | TL | 0ms | 0kb | C++14 | 1.3kb | 2024-05-16 16:01:46 | 2024-05-16 16:01:47 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
const int N = 1e7 + 1;
int fact[N], infact[N];
int power(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
void Init() {
fact[0] = 1;
infact[0] = 1;
for (int i = 1; i < N; i++) {
fact[i] = 1ll * fact[i - 1] * i % mod;
infact[i] = 1ll * infact[i - 1] * power(i, mod - 2) % mod;
}
}
int C(int a, int b) {
return 1ll * fact[a] * infact[b] % mod * infact[a - b] % mod;
}
int main() {
Init();
int n; cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (i - 1 <= n - i) {
// ans = (ans + 1ll * fact[i - 1] * C(n - i, i - 1) % mod * fact[n - i] % mod) % mod;
// ll res = 1;
// for (int j = n - 2 * i + 2; j <= n - i; j++) res = res * j % mod;
// cout << "range: " << n - 2 * i + 2 << ' ' << n - i << '\n';
// ans = (ans + 1ll * fact[n - i] * res % mod) % mod;
ans = (ans + 1ll * fact[n - i] * fact[n - i] % mod * infact[n - 2 * i + 1] % mod) % mod;
}
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
1