QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74067 | #4812. Counting Sequence | KHIN | WA | 104ms | 22644kb | C++14 | 2.0kb | 2023-01-30 15:31:46 | 2023-01-30 15:31:47 |
Judging History
answer
# include <cstdlib>
# include <cstring>
# include <numeric>
# include <cstdio>
namespace khin {
using namespace std;
namespace main {
inline namespace source {}
namespace c { void main(); }
}
}
int main() { khin::main::c::main(); }
namespace khin::main::c {
constexpr uint mod(998'244'353);
constexpr uint& add_eq(uint& x, uint const y)
{ return x = x + y < mod ? x + y : x + y - mod; }
constexpr uint qpow(uint a, uint n) {
uint r(1);
while (n) {
if (n & 0b1) r = 1ul * r * a % mod;
a = 1ul * a * a % mod, n >>= 1;
}
return r;
}
constexpr uint inv(uint const x) { return qpow(x, mod - 2); }
constexpr uint frac(uint const x, uint const y)
{ return 1ul * x * inv(y) % mod; }
constexpr uint n_max(300'000), b(774);
uint n; uint c; uint f[4 * b][2 * b], g[2][n_max];
uint calc0() {
uint const s(4 * b);
for (uint i(1); i < b; ++i) f[i % s][i] = 1;
for (uint i(1); i < n; ++i) {
for (uint j(1); j < 2 * b; ++j) {
uint const val(f[i % s][j]); if (!val) continue;
if (j - 1) add_eq(f[(i + j - 1) % s][j - 1], 1ul * val * 1 % mod);
if (j + 1) add_eq(f[(i + j + 1) % s][j + 1], 1ul * val * c % mod);
}
memset(f[i % s], 0x00, sizeof f[i % s]);
}
return accumulate(f[n % s], f[n % s] + 2 * b, 0ul) % mod;
}
uint calc1() {
uint res(n >= b);
g[0][0] = 1;
for (uint i(1); i < b; ++i) {
memset(g[i % 2], 0x00, sizeof g[i % 2]);
for (uint j(0); j < n; ++j) if (g[(i - 1) % 2][j]) {
add_eq(g[i % 2][j + i], 1ul * g[(i - 1) % 2][j] * 1 % mod);
add_eq(g[i % 2][j + 0], 1ul * g[(i - 1) % 2][j] * c % mod);
}
for (uint j(b); j <= n; ++j) {
uint const x(n - j * (i + 1));
if (x % 2 != i * (i + 1) / 2 % 2) continue;
uint const y((x + i * (i + 1) / 2) / 2);
if (y < n) add_eq(res, g[i % 2][y]);
}
}
return res;
}
void main() {
scanf("%u%u", &n, &c);
printf("%u\n", (calc0() + calc1()) % mod);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 33ms
memory: 9140kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 38ms
memory: 9056kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 53ms
memory: 19212kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 34ms
memory: 10304kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 37ms
memory: 8612kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 34ms
memory: 9580kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 34ms
memory: 9644kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 33ms
memory: 8900kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 33ms
memory: 8600kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 39ms
memory: 10100kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 36ms
memory: 9540kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 38ms
memory: 12484kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 49ms
memory: 19048kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: 0
Accepted
time: 48ms
memory: 22644kb
input:
3000 998244352
output:
71841227
result:
ok 1 number(s): "71841227"
Test #15:
score: 0
Accepted
time: 53ms
memory: 22548kb
input:
3000 555555555
output:
79880116
result:
ok 1 number(s): "79880116"
Test #16:
score: 0
Accepted
time: 62ms
memory: 22644kb
input:
4321 1234
output:
949603993
result:
ok 1 number(s): "949603993"
Test #17:
score: 0
Accepted
time: 60ms
memory: 22620kb
input:
5000 0
output:
5
result:
ok 1 number(s): "5"
Test #18:
score: 0
Accepted
time: 64ms
memory: 22616kb
input:
5000 88888777
output:
833064960
result:
ok 1 number(s): "833064960"
Test #19:
score: 0
Accepted
time: 69ms
memory: 22548kb
input:
5000 35557777
output:
696388498
result:
ok 1 number(s): "696388498"
Test #20:
score: -100
Wrong Answer
time: 104ms
memory: 22552kb
input:
10000 123456
output:
461866116
result:
wrong answer 1st numbers differ - expected: '434296902', found: '461866116'