QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#145204 | #6736. Alice and Bob | berarchegas# | AC ✓ | 155ms | 81764kb | C++17 | 1.3kb | 2023-08-22 00:20:52 | 2023-08-22 00:20:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 998244353;
const int MAXN = 1e7 + 5;
const ll INF = 2e18;
int fat[MAXN], inv[MAXN];
ll fexp(ll b, ll e) {
ll ans = 1;
while (e) {
if (e&1) ans = (ans * b) % MOD;
b = (b * b) % MOD;
e >>= 1;
}
return ans;
}
void precalc() {
fat[0] = 1;
for (int i = 1; i < MAXN; i++) fat[i] = (1ll * i * fat[i - 1]) % MOD;
inv[MAXN - 1] = fexp(fat[MAXN - 1], MOD - 2);
for (int i = MAXN - 2; i >= 0; i--) inv[i] = ((i + 1ll) * inv[i + 1]) % MOD;
}
int nck(int n, int k) {
if (k > n || k < 0 || n < 0) return 0;
return (((1ll * fat[n] * inv[k]) % MOD) * 1ll * inv[n - k]) % MOD;
}
void add(int &a, int b) {
a += b;
if (a >= MOD) a -= MOD;
if (a < 0) a += MOD;
}
int mul(int a, int b) {
return (1ll * a * b) % MOD;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
precalc();
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) {
// primeiro elemento
add(ans, mul(fat[i - 1], mul(nck(n - i, i - 1), fat[n - i])));
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 81ms
memory: 81604kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 80ms
memory: 81600kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 83ms
memory: 81648kb
input:
10
output:
997920
result:
ok 1 number(s): "997920"
Test #4:
score: 0
Accepted
time: 83ms
memory: 81560kb
input:
100
output:
188898954
result:
ok 1 number(s): "188898954"
Test #5:
score: 0
Accepted
time: 77ms
memory: 81756kb
input:
4
output:
10
result:
ok 1 number(s): "10"
Test #6:
score: 0
Accepted
time: 84ms
memory: 81608kb
input:
8
output:
12336
result:
ok 1 number(s): "12336"
Test #7:
score: 0
Accepted
time: 84ms
memory: 81704kb
input:
16
output:
373118483
result:
ok 1 number(s): "373118483"
Test #8:
score: 0
Accepted
time: 88ms
memory: 81588kb
input:
32
output:
314585464
result:
ok 1 number(s): "314585464"
Test #9:
score: 0
Accepted
time: 84ms
memory: 81764kb
input:
64
output:
627827331
result:
ok 1 number(s): "627827331"
Test #10:
score: 0
Accepted
time: 83ms
memory: 81608kb
input:
128
output:
828497685
result:
ok 1 number(s): "828497685"
Test #11:
score: 0
Accepted
time: 83ms
memory: 81540kb
input:
256
output:
65697890
result:
ok 1 number(s): "65697890"
Test #12:
score: 0
Accepted
time: 83ms
memory: 81592kb
input:
512
output:
854187619
result:
ok 1 number(s): "854187619"
Test #13:
score: 0
Accepted
time: 80ms
memory: 81608kb
input:
1024
output:
513823539
result:
ok 1 number(s): "513823539"
Test #14:
score: 0
Accepted
time: 93ms
memory: 81592kb
input:
1361956
output:
617368199
result:
ok 1 number(s): "617368199"
Test #15:
score: 0
Accepted
time: 126ms
memory: 81724kb
input:
7579013
output:
827172636
result:
ok 1 number(s): "827172636"
Test #16:
score: 0
Accepted
time: 126ms
memory: 81588kb
input:
8145517
output:
710624331
result:
ok 1 number(s): "710624331"
Test #17:
score: 0
Accepted
time: 114ms
memory: 81648kb
input:
6140463
output:
707600568
result:
ok 1 number(s): "707600568"
Test #18:
score: 0
Accepted
time: 105ms
memory: 81592kb
input:
3515281
output:
698302413
result:
ok 1 number(s): "698302413"
Test #19:
score: 0
Accepted
time: 119ms
memory: 81596kb
input:
6969586
output:
69470392
result:
ok 1 number(s): "69470392"
Test #20:
score: 0
Accepted
time: 94ms
memory: 81716kb
input:
2888636
output:
433579983
result:
ok 1 number(s): "433579983"
Test #21:
score: 0
Accepted
time: 155ms
memory: 81604kb
input:
9999998
output:
758172780
result:
ok 1 number(s): "758172780"
Test #22:
score: 0
Accepted
time: 134ms
memory: 81612kb
input:
9999999
output:
605195495
result:
ok 1 number(s): "605195495"
Test #23:
score: 0
Accepted
time: 142ms
memory: 81604kb
input:
10000000
output:
866813682
result:
ok 1 number(s): "866813682"