QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#383635 | #6736. Alice and Bob | qzhfx# | AC ✓ | 159ms | 81828kb | C++23 | 2.9kb | 2024-04-09 16:07:53 | 2024-04-09 16:07:55 |
Judging History
answer
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math,no-stack-protector")
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = int64_t;
using LL = long long;
using ull = uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using pii = pair<ll, ll>;
const int mod = 998244353;
const int N = 1e7 + 7;
const int maxn = 1e5 + 100;
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1ll * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1ll * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a) { int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a) { int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a) { return ModInt(1ll * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a) { return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t) {return is >> t.x;}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while (n) {
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<mod>;
mint jc[N], ijc[N];
void init(int n) {
jc[0] = 1;
for (int i = 1; i <= n; i++) {
jc[i] = jc[i - 1] * i;
}
ijc[n] = (mint)1 / jc[n];
for(int i=n-1;i>=0;i--){
ijc[i] = ijc[i + 1] * (i + 1);
}
}
mint C(int n,int m){
if(m > n)return 0;
return jc[n]*ijc[m]*ijc[n - m];
}
void solve() {
int n;
cin >> n;
init(n);
mint ans = 0;
for (int i = 1; i <= n; i++) {
ans += C(n-i,i - 1) * jc[i - 1] * jc[n - i];
}
// ans = jc[n] - ans;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _;
_ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 81744kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 15ms
memory: 81756kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 27ms
memory: 81760kb
input:
10
output:
997920
result:
ok 1 number(s): "997920"
Test #4:
score: 0
Accepted
time: 39ms
memory: 81664kb
input:
100
output:
188898954
result:
ok 1 number(s): "188898954"
Test #5:
score: 0
Accepted
time: 8ms
memory: 81676kb
input:
4
output:
10
result:
ok 1 number(s): "10"
Test #6:
score: 0
Accepted
time: 7ms
memory: 81748kb
input:
8
output:
12336
result:
ok 1 number(s): "12336"
Test #7:
score: 0
Accepted
time: 31ms
memory: 81748kb
input:
16
output:
373118483
result:
ok 1 number(s): "373118483"
Test #8:
score: 0
Accepted
time: 34ms
memory: 81696kb
input:
32
output:
314585464
result:
ok 1 number(s): "314585464"
Test #9:
score: 0
Accepted
time: 34ms
memory: 81672kb
input:
64
output:
627827331
result:
ok 1 number(s): "627827331"
Test #10:
score: 0
Accepted
time: 30ms
memory: 81732kb
input:
128
output:
828497685
result:
ok 1 number(s): "828497685"
Test #11:
score: 0
Accepted
time: 23ms
memory: 81824kb
input:
256
output:
65697890
result:
ok 1 number(s): "65697890"
Test #12:
score: 0
Accepted
time: 38ms
memory: 81752kb
input:
512
output:
854187619
result:
ok 1 number(s): "854187619"
Test #13:
score: 0
Accepted
time: 23ms
memory: 81732kb
input:
1024
output:
513823539
result:
ok 1 number(s): "513823539"
Test #14:
score: 0
Accepted
time: 51ms
memory: 81756kb
input:
1361956
output:
617368199
result:
ok 1 number(s): "617368199"
Test #15:
score: 0
Accepted
time: 102ms
memory: 81756kb
input:
7579013
output:
827172636
result:
ok 1 number(s): "827172636"
Test #16:
score: 0
Accepted
time: 136ms
memory: 81732kb
input:
8145517
output:
710624331
result:
ok 1 number(s): "710624331"
Test #17:
score: 0
Accepted
time: 102ms
memory: 81684kb
input:
6140463
output:
707600568
result:
ok 1 number(s): "707600568"
Test #18:
score: 0
Accepted
time: 62ms
memory: 81828kb
input:
3515281
output:
698302413
result:
ok 1 number(s): "698302413"
Test #19:
score: 0
Accepted
time: 117ms
memory: 81760kb
input:
6969586
output:
69470392
result:
ok 1 number(s): "69470392"
Test #20:
score: 0
Accepted
time: 70ms
memory: 81696kb
input:
2888636
output:
433579983
result:
ok 1 number(s): "433579983"
Test #21:
score: 0
Accepted
time: 151ms
memory: 81744kb
input:
9999998
output:
758172780
result:
ok 1 number(s): "758172780"
Test #22:
score: 0
Accepted
time: 139ms
memory: 81764kb
input:
9999999
output:
605195495
result:
ok 1 number(s): "605195495"
Test #23:
score: 0
Accepted
time: 159ms
memory: 81752kb
input:
10000000
output:
866813682
result:
ok 1 number(s): "866813682"