QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624030 | #8635. 圆 | JWRuixi | 100 ✓ | 108ms | 3736kb | C++20 | 1.6kb | 2024-10-09 14:45:37 | 2024-10-09 14:45:37 |
Judging History
answer
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
#endif
constexpr int N = 5e3 + 9;
constexpr int P = 998244353;
int n;
IL constexpr int qpow (int b, int k = P - 2) {
int r = 1;
for (; k; k >>= 1, b = (LL)b * b % P) if (k & 1) r = (LL)r * b % P;
return r;
}
int fc[N], ifc[N];
void init (int Z) {
fc[0] = 1;
L (i, 1, Z) {
fc[i] = (LL)fc[i - 1] * i % P;
}
ifc[Z] = qpow(fc[Z]);
R (i, Z - 1, 0) {
ifc[i] = (LL)ifc[i + 1] * (i + 1) % P;
}
}
int C (int n, int m) {
return (LL)fc[n] * ifc[m] % P * ifc[n - m] % P;
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
init(n);
int ns = 1;
L (i, 1, n - 1) {
int all = C(n, i), k = 0;
if (i == 1) {
if (n <= 3) {
k = all;
} else {
k = 0;
}
} else {
L (x, 0, 2) {
L (y, 0, 2) {
if (x + y < 3 && x + y <= n - i) {
L (t, 0, min(i - 1, (n - i - x - y) / 3)) {
k = (k + (t & 1 ? -1LL : 1LL) * C(i - 1, t) * C(n - x - y - 2 - 3 * t, i - 2)) % P;
}
}
}
}
}
ns = (ns + (LL)(all - k) * qpow(all)) % P;
}
if (ns < 0) {
ns += P;
}
cout << ns << '\n';
}
// I love WHQ!
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3584kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3664kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3588kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3672kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3716kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 0ms
memory: 3588kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 2ms
memory: 3592kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 98ms
memory: 3680kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 108ms
memory: 3612kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 107ms
memory: 3736kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"