提出 #49003466


ソースコード 拡げる

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 1e7 + 10;
const int M = 1e5 + 10;
const int P = 998244353;
void add(int &a, int b) {a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b) {a -= b; a < 0 ? a += P : 0;}
int ksm(int x, int k) {
  int res = 1;
  for(int pw = x; k; (k & 1) ? res = 1ll * res * pw % P : 0, pw = 1ll * pw * pw % P, k >>= 1);
  return res;
}
int fac[N], ifac[N];
void init() {
  fac[0] = ifac[0] = 1;
  for(int i = 1; i < N; i++)fac[i] = 1ll * fac[i - 1] * i % P;
  ifac[N - 1] = ksm(fac[N - 1], P - 2);
  for(int i = N - 2; i; i--)ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P;
  return ;
}
int com(int n, int m) {return n < m || m < 0 ? 0 : 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P;}
int n, m, k;
vector<pii> E;
int work1() {
  vector<int> val[2]; val[0].resize(k + 1); val[1].resize(k + 1);
  for(int i = 0; i <= k; i++)val[i & 1][i] = com(n + i - 1, n - 1);
  for(int i = 0; i < 2; i++)for(int j = 1; j <= k; j++)add(val[i][j], val[i][j - 1]);
  int ans = 0;
  for(int i = 0; i <= n; i++) {
    if(i * (m + 1) > k)break;
    int v = i * (m + 1), o = (i * (m + 1)) & 1;
    int w = 1ll * com(n, i) * val[o][k - v] % P;
    ((i & 1) ? sub(ans, w) : add(ans, w));
  }
  return ans;
}
int f[2][M][2], tmp[M][2];
void DP(int n, int L) {
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= L; j++)
      for(int o = 0; o < 2; o++) {
        f[1][j][o] = f[0][j][o];
        tmp[j][o] = f[0][j][o] = 0;
      }
    for(int j = 0; j <= L; j++) {
      for(int o = 0; o < 2; o++) {
        add(tmp[j][o ^ (j & 1)], f[1][j][o]);
        if(j > m)sub(tmp[j - m - 1][o ^ (j & 1)], f[1][j][o]);
      }
    }
    for(int j = L; ~j; j--) {
      for(int o = 0; o < 2; o++) {
        if(j < L)add(tmp[j][o], tmp[j + 1][o]);
        add(f[0][j][o ^ (j & 1)], tmp[j][o]);
      }
    }
  }
  return ;
}
int work2() {
  for(int i = 0; i <= m * 2; i++)
    for(int j = 0; j < 2; j++)
      f[0][i][j] = 0;
  for(int a = 0; a <= m; a++)
    for(int b = 0; b <= m; b++)
      if((a || b) && a + b <= k)
        f[0][min(k - a - b, a + b - 1)][(a + b) & 1]++;
  DP(n - 2, m * 2);
  int ans = 0;
  for(int i = 0; i <= m * 2; i++)add(ans, f[0][i][0]);
  return 1ll * n * ans % P;
}
int work3() {
  for(int i = 0; i <= m * 2; i++)
    for(int j = 0; j < 2; j++)
      f[0][i][j] = tmp[i][j] = 0;
  for(int a = 0; a <= m; a++) {
    for(int c = 0; c <= m; c++) {
      int x = min(a, c) - max(a, c) - 1, y = k - a - c, l, r;
      // cout << a << ' ' << c << ' ' << x << ' ' << y << endl;
      if(y - x >= 0) {
        l = x; r = x + min(m, (y - x) / 2);
        // cout << l << ' ' << r << endl;
        tmp[max(l, 0)][((a + c) ^ x) & 1]++;
        tmp[max(r + 1, 0)][((a + c) ^ x) & 1]--;
        l = y - m; r = max(l - 1, y - (y - x) / 2 - 1);
        tmp[max(l, 0)][((a + c) ^ y) & 1]++;
        tmp[max(r + 1, 0)][((a + c) ^ y) & 1]--;
      }
      else {
        l = y - m; r = max(l - 1, y);
        tmp[max(l, 0)][((a + c) ^ y) & 1]++;
        tmp[max(r + 1, 0)][((a + c) ^ y) & 1]--;
      }
    }
  }
  for(int i = 0; i <= m * 2; i++) {
    for(int j = 0; j < 2; j++) {
      if(i)add(tmp[i][j], tmp[i - 1][j]);
      add(f[0][i][j ^ (i & 1)], tmp[i][j]);
    }
  }
  DP(n - 3, m * 2);
  int ans = 0;
  for(int i = 0; i <= m * 2; i++)add(ans, f[0][i][0]);
  return 1ll * n * ans % P;
}
int main() {
  init();
  n = read(); m = read(); k = read();
  int ans = ((work1() - work2() + P) % P + work3()) % P;
  // int ans = work3();
  printf("%d\n", ans);
  return 0;
}

提出情報

提出日時
問題 E - Non-Adjacent Matching
ユーザ thebighead
言語 C++ 20 (gcc 12.2)
得点 800
コード長 3992 Byte
結果 AC
実行時間 602 ms
メモリ 151412 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 800 / 800
結果
AC × 3
AC × 50
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 03_large_01.txt, 03_large_02.txt, 03_large_03.txt, 03_large_04.txt, 03_large_05.txt, 03_large_06.txt, 03_large_07.txt, 03_large_08.txt, 03_large_09.txt, 03_large_10.txt, 03_large_11.txt, 03_large_12.txt, 03_large_13.txt, 03_large_14.txt, 03_large_15.txt, 03_large_16.txt, 03_large_17.txt, 03_large_18.txt, 03_large_19.txt, 03_large_20.txt, 03_large_21.txt, 03_large_22.txt, 03_large_23.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 112 ms 81828 KiB
00_sample_02.txt AC 111 ms 81880 KiB
00_sample_03.txt AC 113 ms 81904 KiB
01_small_01.txt AC 111 ms 81904 KiB
01_small_02.txt AC 111 ms 81956 KiB
01_small_03.txt AC 111 ms 81884 KiB
01_small_04.txt AC 111 ms 81788 KiB
01_small_05.txt AC 111 ms 81700 KiB
01_small_06.txt AC 111 ms 81764 KiB
01_small_07.txt AC 111 ms 81960 KiB
01_small_08.txt AC 112 ms 81956 KiB
01_small_09.txt AC 111 ms 81776 KiB
01_small_10.txt AC 111 ms 81780 KiB
02_random_01.txt AC 204 ms 81880 KiB
02_random_02.txt AC 401 ms 82016 KiB
02_random_03.txt AC 402 ms 81976 KiB
02_random_04.txt AC 335 ms 82064 KiB
02_random_05.txt AC 225 ms 81940 KiB
02_random_06.txt AC 136 ms 83340 KiB
02_random_07.txt AC 386 ms 87764 KiB
02_random_08.txt AC 178 ms 87540 KiB
02_random_09.txt AC 504 ms 97076 KiB
02_random_10.txt AC 357 ms 110472 KiB
03_large_01.txt AC 601 ms 151340 KiB
03_large_02.txt AC 588 ms 82076 KiB
03_large_03.txt AC 577 ms 133436 KiB
03_large_04.txt AC 602 ms 151412 KiB
03_large_05.txt AC 343 ms 81896 KiB
03_large_06.txt AC 465 ms 82068 KiB
03_large_07.txt AC 346 ms 82012 KiB
03_large_08.txt AC 388 ms 81900 KiB
03_large_09.txt AC 417 ms 82164 KiB
03_large_10.txt AC 398 ms 94204 KiB
03_large_11.txt AC 418 ms 111288 KiB
03_large_12.txt AC 362 ms 88588 KiB
03_large_13.txt AC 402 ms 92020 KiB
03_large_14.txt AC 390 ms 114956 KiB
03_large_15.txt AC 416 ms 115304 KiB
03_large_16.txt AC 500 ms 125416 KiB
03_large_17.txt AC 477 ms 134832 KiB
03_large_18.txt AC 479 ms 132964 KiB
03_large_19.txt AC 400 ms 121872 KiB
03_large_20.txt AC 386 ms 120268 KiB
03_large_21.txt AC 468 ms 132176 KiB
03_large_22.txt AC 488 ms 135840 KiB
03_large_23.txt AC 376 ms 119728 KiB
04_handmade_01.txt AC 443 ms 82092 KiB
04_handmade_02.txt AC 111 ms 81768 KiB
04_handmade_03.txt AC 155 ms 82136 KiB
04_handmade_04.txt AC 155 ms 81912 KiB