QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74076 | #4812. Counting Sequence | KHIN | WA | 246ms | 13308kb | C++14 | 2.4kb | 2023-01-30 16:03:19 | 2023-01-30 16:03:22 |
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(775);
uint n; uint c; uint f[2 * b][2 * b], g[2][n_max];
uint calc0() {
uint const s(2 * 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]);
}
// uint const res(accumulate(f[n % s], f[n % s] + 2 * b, 0ul) % mod);
// fprintf(stderr, "%s: %u\n", __func__, res);
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]);
if (y < n && g[i % 2][y] && j == b && false) {
fprintf(stderr, "pow: %u\n", qpow(c, i - 3));
fprintf(stderr, "pow: %u\n", qpow(c, i - 2));
fprintf(stderr, "pow: %u\n", qpow(c, i - 1));
fprintf(stderr, "%u %u %i %u\n", j, i, x, g[i % 2][y]);
}
}
}
// fprintf(stderr, "%s: %u\n", __func__, res);
return res;
}
void main() {
scanf("%u%u", &n, &c);
printf("%u\n", (calc0() + calc1()) % mod);
}
}
详细
Test #1:
score: 100
Accepted
time: 34ms
memory: 9340kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 35ms
memory: 9680kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 53ms
memory: 13280kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 34ms
memory: 10348kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 34ms
memory: 9088kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 41ms
memory: 9108kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 34ms
memory: 8876kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 38ms
memory: 10092kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 34ms
memory: 9824kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 30ms
memory: 9516kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 36ms
memory: 10256kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 39ms
memory: 12448kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 41ms
memory: 13268kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: 0
Accepted
time: 47ms
memory: 13264kb
input:
3000 998244352
output:
71841227
result:
ok 1 number(s): "71841227"
Test #15:
score: 0
Accepted
time: 45ms
memory: 13284kb
input:
3000 555555555
output:
79880116
result:
ok 1 number(s): "79880116"
Test #16:
score: 0
Accepted
time: 67ms
memory: 13212kb
input:
4321 1234
output:
949603993
result:
ok 1 number(s): "949603993"
Test #17:
score: 0
Accepted
time: 51ms
memory: 13308kb
input:
5000 0
output:
5
result:
ok 1 number(s): "5"
Test #18:
score: 0
Accepted
time: 68ms
memory: 13224kb
input:
5000 88888777
output:
833064960
result:
ok 1 number(s): "833064960"
Test #19:
score: 0
Accepted
time: 63ms
memory: 13212kb
input:
5000 35557777
output:
696388498
result:
ok 1 number(s): "696388498"
Test #20:
score: 0
Accepted
time: 99ms
memory: 13308kb
input:
10000 123456
output:
434296902
result:
ok 1 number(s): "434296902"
Test #21:
score: 0
Accepted
time: 173ms
memory: 13212kb
input:
20000 555555
output:
34806915
result:
ok 1 number(s): "34806915"
Test #22:
score: -100
Wrong Answer
time: 246ms
memory: 13300kb
input:
30000 777888999
output:
41686115
result:
wrong answer 1st numbers differ - expected: '58443551', found: '41686115'