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 |
---|---|---|---|---|---|---|---|---|---|
#73192 | #4812. Counting Sequence | Acestar | WA | 3ms | 8028kb | C++14 | 1.1kb | 2023-01-22 23:30:41 | 2023-01-22 23:30:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int M = 800;
const int mod = 998244353;
int add(int x) {return x < mod ? x : x - mod;}
int n, c, B;
int f[M << 1][M << 1], g[2][N << 1], ans;
int main()
{
cin >> n >> c;
while(B * (B + 1) / 2 < n) B++;
// a1 <= B
int BB = 2 * B;
for(int i = 1; i <= n; i++)
{
int I = i % BB;
for(int j = 1; j <= min(i, BB); j++)
f[I][j] = add(f[(I - j + BB) % BB][j - 1] + 1ll * f[(I - j + BB) % BB][j + 1] * c % mod);
if(i < B) f[I][i]++;
}
for(int i = 1; i <= BB; i++) ans = add(ans + f[n % BB][i]);
// a1 > B
if(B <= n) ans++;
g[1][0 + N] = 1;
for(int i = 2, I = 0; i * B <= 2 * n; i++, I ^= 1)
for(int j = max(-i * (i + 1) / 2, -i * B + 1); j <= min(i * (i + 1) / 2, n - i * B); j++)
{
g[I][j + N] = add(g[!I][j - (i - 1) + N] + 1ll * g[!I][j + (i - 1) + N] * c % mod);
if((n - j) % i == 0) ans = add(ans + g[I][j + N]);
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5400kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7392kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 3ms
memory: 8028kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5412kb
input:
1 998244352
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'