QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74066 | #4812. Counting Sequence | KHIN | WA | 18ms | 21060kb | C++14 | 1.8kb | 2023-01-30 15:25:03 | 2023-01-30 15:25:05 |
Judging History
answer
# include <cstdlib>
# 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);
}
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) {
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: 1ms
memory: 9748kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 7680kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 18ms
memory: 18676kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 2ms
memory: 9728kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 7736kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7640kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 0ms
memory: 7640kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 0ms
memory: 9736kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 0ms
memory: 9676kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 4ms
memory: 9740kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 0ms
memory: 9680kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 6ms
memory: 11068kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 12ms
memory: 18432kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: -100
Wrong Answer
time: 16ms
memory: 21060kb
input:
3000 998244352
output:
71841228
result:
wrong answer 1st numbers differ - expected: '71841227', found: '71841228'