QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#74065#4812. Counting SequenceKHINWA 0ms9740kbC++141.8kb2023-01-30 15:24:302023-01-30 15:24:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-30 15:24:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9740kb
  • [2023-01-30 15:24:30]
  • 提交

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(1);
    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: 0
Wrong Answer
time: 0ms
memory: 9740kb

input:

5 3

output:

9

result:

wrong answer 1st numbers differ - expected: '8', found: '9'