QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74061 | #4812. Counting Sequence | KHIN | WA | 17ms | 35396kb | C++14 | 1.8kb | 2023-01-30 15:19:30 | 2023-01-30 15:19:32 |
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[b][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() {
g[0][0] = 1;
for (uint i(1); i < b; ++i) for (uint j(0); j < n; ++j) {
add_eq(g[i][j + i], 1ul * g[i - 1][j] * 1 % mod);
add_eq(g[i][j + 0], 1ul * g[i - 1][j] * c % mod);
}
uint res(0);
for (uint i(b); i <= n; ++i) for (uint j(0); i * (j + 1) <= n; ++j) {
uint const x(n - i * (j + 1));
if (x % 2 == j * (j + 1) / 2 % 2)
add_eq(res, g[j][(x + j * (j + 1) / 2) / 2]);
}
return res;
}
void main() {
scanf("%u%u", &n, &c);
printf("%u\n", (calc0() + calc1()) % mod);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11900kb
input:
5 3
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11976kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 17ms
memory: 27544kb
input:
2022 39
output:
273239559
result:
ok 1 number(s): "273239559"
Test #4:
score: 0
Accepted
time: 0ms
memory: 13928kb
input:
1 998244352
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 4ms
memory: 11984kb
input:
1 12345678
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 4ms
memory: 12004kb
input:
20 998998
output:
643731701
result:
ok 1 number(s): "643731701"
Test #7:
score: 0
Accepted
time: 0ms
memory: 12008kb
input:
23 123
output:
947753998
result:
ok 1 number(s): "947753998"
Test #8:
score: 0
Accepted
time: 1ms
memory: 12128kb
input:
50 5555
output:
745339864
result:
ok 1 number(s): "745339864"
Test #9:
score: 0
Accepted
time: 1ms
memory: 12060kb
input:
60 6666
output:
690992218
result:
ok 1 number(s): "690992218"
Test #10:
score: 0
Accepted
time: 0ms
memory: 12272kb
input:
100 50
output:
169678588
result:
ok 1 number(s): "169678588"
Test #11:
score: 0
Accepted
time: 6ms
memory: 13588kb
input:
500 88888
output:
216149701
result:
ok 1 number(s): "216149701"
Test #12:
score: 0
Accepted
time: 0ms
memory: 18456kb
input:
1000 213456
output:
270989457
result:
ok 1 number(s): "270989457"
Test #13:
score: 0
Accepted
time: 12ms
memory: 28564kb
input:
2000 119988
output:
756425375
result:
ok 1 number(s): "756425375"
Test #14:
score: -100
Wrong Answer
time: 16ms
memory: 35396kb
input:
3000 998244352
output:
71841226
result:
wrong answer 1st numbers differ - expected: '71841227', found: '71841226'