QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#411623 | #6678. Gem Island 2 | le0n# | TL | 311ms | 245760kb | C++14 | 1.1kb | 2024-05-15 16:48:50 | 2024-05-15 16:48:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353, N = 3e7 + 5;
int fac[N], inv[N], f[N], g[N];
int qpow(int x, int y)
{
int ans = 1;
while(y)
{
if(y & 1)
ans = (ll)ans * x % mod;
x = (ll)x * x % mod;
y >>= 1;
}
return ans;
}
void prep(int n)
{
int i;
fac[0] = 1;
for(i = 1; i <= n; i++)
fac[i] = (ll)fac[i - 1] * i % mod;
inv[n] = qpow(fac[n], mod - 2);
for(i = n; i >= 1; i--)
inv[i - 1] = (ll)inv[i] * i % mod;
}
int C(int x, int y)
{
return (x < y || y < 0) ? 0 : ((ll)fac[x] * inv[y] % mod * inv[x - y] % mod);
}
int main()
{
int n, d, r, i, j, ans = 0, tmp;
prep(3e7);
scanf("%d%d%d", &n, &d, &r);
for(i = 1; i <= n; i++)
{
g[i] = ((ll)i * C(i - 2, r - 2) + mod - (ll)r * C(i - 1, r - 1) % mod) % mod;
if((i + r - 1) & 1)
g[i] = mod - g[i];
}
g[1] = 1;
for(i = 1; i <= n; i++)
{
tmp = 0;
for(j = 0; j <= d / i; j++)
tmp = (tmp + C(d - i * j + n - 1, n - 1)) % mod;
ans = (ans + (ll)C(n, i) * tmp % mod * g[i]) % mod;
}
ans = (ll)ans * qpow(C(d + n - 1, n - 1), mod - 2) % mod;
printf("%d\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 245ms
memory: 238040kb
input:
2 3 1
output:
499122180
result:
ok 1 number(s): "499122180"
Test #2:
score: 0
Accepted
time: 284ms
memory: 238164kb
input:
3 3 2
output:
698771052
result:
ok 1 number(s): "698771052"
Test #3:
score: 0
Accepted
time: 277ms
memory: 238140kb
input:
5 10 3
output:
176512750
result:
ok 1 number(s): "176512750"
Test #4:
score: 0
Accepted
time: 282ms
memory: 238164kb
input:
5 4 3
output:
71303175
result:
ok 1 number(s): "71303175"
Test #5:
score: 0
Accepted
time: 245ms
memory: 238212kb
input:
37 47 12
output:
962577218
result:
ok 1 number(s): "962577218"
Test #6:
score: 0
Accepted
time: 266ms
memory: 238204kb
input:
29 50 26
output:
175627840
result:
ok 1 number(s): "175627840"
Test #7:
score: 0
Accepted
time: 267ms
memory: 238208kb
input:
298 498 221
output:
765832019
result:
ok 1 number(s): "765832019"
Test #8:
score: 0
Accepted
time: 259ms
memory: 238136kb
input:
497 456 243
output:
414028615
result:
ok 1 number(s): "414028615"
Test #9:
score: 0
Accepted
time: 276ms
memory: 238576kb
input:
114514 1926 817
output:
691374994
result:
ok 1 number(s): "691374994"
Test #10:
score: 0
Accepted
time: 282ms
memory: 245760kb
input:
1919810 1554 1999
output:
3553
result:
ok 1 number(s): "3553"
Test #11:
score: 0
Accepted
time: 311ms
memory: 245664kb
input:
1926817 1514 1001
output:
685086550
result:
ok 1 number(s): "685086550"
Test #12:
score: 0
Accepted
time: 266ms
memory: 243804kb
input:
1432132 1425 1425
output:
2850
result:
ok 1 number(s): "2850"
Test #13:
score: -100
Time Limit Exceeded
input:
14999999 15000000 14999999