QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354664 | #5546. Sharing Bread | SolitaryDream# | AC ✓ | 501ms | 25948kb | C++14 | 2.6kb | 2024-03-15 20:50:33 | 2024-03-15 20:50:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> poly;
const int N = 1e6;
const int p = 998244353;
inline int Qpow(int x, int y = p - 2) {
int ans = 1;
for (; y; y >>= 1, x = 1ll * x * x % p) if (y & 1) ans = 1ll * ans * x % p;
return ans;
}
namespace Core {
int a[N], b[N], w[N], rev[N];
inline void NTT(int *a, int len) {
for (int i = 1; i < len; ++i) if (i > rev[i]) swap(a[i], a[rev[i]]);
for (int d = 1; d < len; d <<= 1)
for (int m = d << 1, i = 0; i < len; i += m)
for (int j = 0; j < d; ++j) {
int x = a[i + j], y = 1ll * a[i + j + d] * w[len / m * j] % p;
a[i + j] = (x + y >= p ? x + y - p : x + y);
a[i + j + d] = (x - y < 0 ? x - y + p : x - y);
}
}
}
inline poly operator*(poly va, poly vb) {
// poly c(a.size() + b.size() - 1);
// for (int i = 0; i < a.size(); ++i)
// for (int j = 0; j < b.size(); ++j)
// c[i + j] = (c[i + j] + 1ll * a[i] * b[j]) % p;
using namespace Core;
int len = 1; while (len < (int)va.size() + (int)vb.size() - 1) len <<= 1;
for (int i = 0; i < len; ++i) a[i] = (i < (int)va.size() ? va[i] : 0);
for (int i = 0; i < len; ++i) b[i] = (i < (int)vb.size() ? vb[i] : 0);
for (int i = 1; i < len; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1 ? len >> 1 : 0);
w[0] = 1; w[1] = Qpow(3, (p - 1) / len);
for (int i = 2; i < len; ++i) w[i] = 1ll * w[i - 1] * w[1] % p;
NTT(a, len); NTT(b, len);
for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * b[i] % p;
reverse(a + 1, a + len); NTT(a, len);
poly c(va.size() + vb.size() - 1);
for (int i = 0, invlen = Qpow(len); i < (int)c.size(); ++i) c[i] = 1ll * a[i] * invlen % p;
return c;
}
inline poly Fixlen(poly a, int len) {
a.resize(len);
return a;
}
inline poly Qpow(int lim, poly x, int y = p - 2) {
poly ans = x; --y;
for (; y; y >>= 1, x = Fixlen(x * x, lim)) if (y & 1) ans = Fixlen(x * ans, lim);
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(m + 1), finv(m + 1), fac(m + 1);
a[0] = 1;
finv[0] = 1;
fac[0] = 1;
for (int i = 1; i <= m; ++i) {
finv[i] = 1ll * finv[i - 1] * Qpow(i) % p;
fac[i] = 1ll * fac[i - 1] * i % p;
a[i] = 1ll * Qpow(i + 1, i - 1) * finv[i] % p;
}
vector<int> ans = Qpow(m + 1, a, n - m + 1);
int rst = 1ll * ans[m] * fac[m] % p;
cout << rst << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9772kb
input:
4 3
output:
50
result:
ok single line: '50'
Test #2:
score: 0
Accepted
time: 0ms
memory: 9752kb
input:
10 1
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
277 277
output:
124662617
result:
ok single line: '124662617'
Test #6:
score: 0
Accepted
time: 0ms
memory: 9756kb
input:
426 1
output:
426
result:
ok single line: '426'
Test #7:
score: 0
Accepted
time: 0ms
memory: 9752kb
input:
200000 1
output:
200000
result:
ok single line: '200000'
Test #8:
score: 0
Accepted
time: 41ms
memory: 7052kb
input:
200000 200000
output:
950017432
result:
ok single line: '950017432'
Test #9:
score: 0
Accepted
time: 453ms
memory: 21652kb
input:
200000 100000
output:
280947286
result:
ok single line: '280947286'
Test #10:
score: 0
Accepted
time: 479ms
memory: 20516kb
input:
200000 84731
output:
211985425
result:
ok single line: '211985425'
Test #11:
score: 0
Accepted
time: 501ms
memory: 17712kb
input:
200000 124713
output:
716696526
result:
ok single line: '716696526'
Test #12:
score: 0
Accepted
time: 237ms
memory: 16436kb
input:
129179 49655
output:
506429515
result:
ok single line: '506429515'
Test #13:
score: 0
Accepted
time: 98ms
memory: 10984kb
input:
87518 26040
output:
808454539
result:
ok single line: '808454539'
Test #14:
score: 0
Accepted
time: 57ms
memory: 10040kb
input:
178355 10116
output:
361555714
result:
ok single line: '361555714'
Test #15:
score: 0
Accepted
time: 2ms
memory: 9936kb
input:
2 1
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 249ms
memory: 14568kb
input:
192733 52550
output:
67181038
result:
ok single line: '67181038'
Test #17:
score: 0
Accepted
time: 235ms
memory: 15836kb
input:
76689 36632
output:
717949287
result:
ok single line: '717949287'
Test #18:
score: 0
Accepted
time: 0ms
memory: 9772kb
input:
200000 9
output:
158524471
result:
ok single line: '158524471'
Test #19:
score: 0
Accepted
time: 173ms
memory: 25948kb
input:
200000 199998
output:
879727659
result:
ok single line: '879727659'
Test #20:
score: 0
Accepted
time: 2ms
memory: 9796kb
input:
199952 1
output:
199952
result:
ok single line: '199952'
Test #21:
score: 0
Accepted
time: 44ms
memory: 7000kb
input:
199947 199947
output:
339118685
result:
ok single line: '339118685'
Test #22:
score: 0
Accepted
time: 486ms
memory: 17424kb
input:
199956 99978
output:
135867461
result:
ok single line: '135867461'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
2 2
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 2ms
memory: 9756kb
input:
10 3
output:
968
result:
ok single line: '968'
Test #25:
score: 0
Accepted
time: 2ms
memory: 9660kb
input:
10 5
output:
87846
result:
ok single line: '87846'
Test #26:
score: 0
Accepted
time: 1ms
memory: 10000kb
input:
10 9
output:
428717762
result:
ok single line: '428717762'
Test #27:
score: 0
Accepted
time: 0ms
memory: 9716kb
input:
279 166
output:
945780025
result:
ok single line: '945780025'
Test #28:
score: 0
Accepted
time: 0ms
memory: 9744kb
input:
361 305
output:
926296326
result:
ok single line: '926296326'
Test #29:
score: 0
Accepted
time: 0ms
memory: 9748kb
input:
305 262
output:
465560336
result:
ok single line: '465560336'