QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#472100#6417. Classical Summation ProblemUESTC_OldEastWest#WA 8ms18756kbC++172.0kb2024-07-11 14:31:352024-07-11 14:31:36

Judging History

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

  • [2024-07-11 14:31:36]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:18756kb
  • [2024-07-11 14:31:35]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;
#define int ll
const int N = 1e6 + 5;
const int MOD = 998244353;

std::vector<int> fac, inv;

int QSM (int x, int p) {
  int ans = 1;
  while (p) {
    if (p & 1) ans = 1ll * ans * x % MOD;
    p >>= 1, x = 1ll * x * x % MOD;
  }
  return ans;
}

void Prep() {
  fac = std::vector<int> (N, 1);
  inv = std::vector<int> (N, 1);
  for (int i = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
  inv[N - 1] = QSM(fac[N - 1], MOD - 2);
  for (int i = N - 2; i >= 1; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
}

int C (int n, int m) {
  if (n < m) return 0;
  else return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

void force(int n, int k) {
  std::vector<int> cnt(n + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int p1 = 1; p1 <= n; ++p1) {
        for (int p2 = 1; p2 <= n; ++p2) {
          std::vector<int> vec;
          vec.emplace_back(i);
          vec.emplace_back(j);
          vec.emplace_back(p1);
          vec.emplace_back(p2);
          sort(vec.begin(), vec.end());
          ++cnt[vec[k / 2 - 1]];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = (ans + 1ll * i * cnt[i] % MOD) % MOD;
  std::cout << ans << '\n';
}

void charming() {
  int n, k; std::cin >> n >> k;
  int ans = 0;
  if (k & 1) {
    ans = 1ll * (n + 1) * QSM(2, MOD - 2) % MOD * QSM(n, k) % MOD;
    std::cout << ans << '\n';
    return;
  }
  int cnt = 0;
  for (int i = 1, ncnt; i <= n; ++i) {
    ncnt = 1ll * C(k, k / 2) * (C(k / 2 + i - 1, k / 2) - C(k / 2 + i - 2, k / 2)) % MOD;
    ncnt = 1ll * ncnt * C(n - i + k / 2 - 1, k / 2) % MOD;
    cnt = (cnt + ncnt) % MOD;
    ans = (ans + 1ll * ncnt * i % MOD) % MOD;
    // std::cout << i << " " << cnt << '\n';
  }
  ans = (ans + 1ll * (n + 1) * QSM(2, MOD - 2) % MOD * (QSM(n, k) - cnt) % MOD) % MOD;
  ans = (ans + MOD) % MOD;
  std::cout << ans << '\n';
  
  // force(n, k);
}

signed main() {
  Prep();
  charming();
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 18680kb

input:

3 2

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 8ms
memory: 18608kb

input:

5 3

output:

375

result:

ok 1 number(s): "375"

Test #3:

score: 0
Accepted
time: 8ms
memory: 18756kb

input:

2 2

output:

5

result:

ok 1 number(s): "5"

Test #4:

score: 0
Accepted
time: 7ms
memory: 18656kb

input:

10 9

output:

508778235

result:

ok 1 number(s): "508778235"

Test #5:

score: 0
Accepted
time: 7ms
memory: 18656kb

input:

69 3

output:

11497815

result:

ok 1 number(s): "11497815"

Test #6:

score: 0
Accepted
time: 7ms
memory: 18564kb

input:

994 515

output:

33689623

result:

ok 1 number(s): "33689623"

Test #7:

score: -100
Wrong Answer
time: 7ms
memory: 18676kb

input:

4476 6182

output:

758461339

result:

wrong answer 1st numbers differ - expected: '114894183', found: '758461339'