結果

問題 No.1963 Subset Mex
ユーザー jianfeng zhujianfeng zhu
提出日時 2022-07-02 19:59:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 4,000 ms
コード長 2,050 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 68,408 KB
実行使用メモリ 7,920 KB
最終ジャッジ日時 2023-08-18 11:58:58
合計ジャッジ時間 2,413 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,424 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,552 KB
testcase_07 AC 3 ms
4,404 KB
testcase_08 AC 3 ms
4,520 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 10 ms
7,692 KB
testcase_13 AC 10 ms
7,728 KB
testcase_14 AC 10 ms
7,772 KB
testcase_15 AC 10 ms
7,712 KB
testcase_16 AC 10 ms
7,772 KB
testcase_17 AC 10 ms
7,744 KB
testcase_18 AC 10 ms
7,756 KB
testcase_19 AC 10 ms
7,728 KB
testcase_20 AC 9 ms
7,660 KB
testcase_21 AC 10 ms
7,788 KB
testcase_22 AC 11 ms
7,724 KB
testcase_23 AC 10 ms
7,828 KB
testcase_24 AC 11 ms
7,784 KB
testcase_25 AC 10 ms
7,772 KB
testcase_26 AC 11 ms
7,756 KB
testcase_27 AC 10 ms
7,728 KB
testcase_28 AC 10 ms
7,760 KB
testcase_29 AC 10 ms
7,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>

using namespace std;

const int N = 105, mod = 998244353;
int n, s[N], f[N][N][N], dp[N][N];

int add(int x, int y) { return x + y < mod ? x + y : x + y - mod; }
int sub(int x, int y) { return x < y ? x + mod - y : x - y; }

int query(int x) {
  int y = 1, r = 0;
  for (int i = x - 1; i; i--) {
    if (y <= s[i])
      r += s[i] - y;
    else
      y = 2 * y - s[i];
    if (y > n)
      return n + 1;
  }
  return max(0, y - r - s[0]);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x, s[x]++;
  }

  f[101][0][0] = 1;
  for (int i = 100; i; i--) {
    for (int j = 0; j <= s[i]; j++) {
      int x = s[i] - j;
      for (int k = 0; k <= n; k++) {
        if (k >= x) {
          if (k + k - x <= n) {
            for (int t = 0; t <= n; t++)
              f[i][2 * k - x][t] = add(f[i][2 * k - x][t], f[i + 1][k][t]);
          }
        } else {
          for (int t = 0; t + x - k <= n; t++)
            f[i][k][t + x - k] = add(f[i][k][t + x - k], f[i + 1][k][t]);
        }
      }
    }
    for (int j = 1; j <= n / i; j++) {
      for (int k = 0; 2 * k + j <= n; k++)
        for (int t = 0; t <= n; t++)
          f[i][2 * k + j][t] = add(f[i][2 * k + j][t], f[i + 1][k][t]);
    }
  }

  int ans = mod - 1;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      for (int k = max(0, i + j - s[0]); k <= n; k++)
        ans = add(ans, f[1][j][k]);
  dp[101][0] = 1;
  for (int i = 100; i; i--)
    for (int j = 0; j <= n; j++)
      for (int x = 0; x <= s[i] && x + j <= n; x++)
        dp[i][j + x] = add(dp[i][j + x], dp[i + 1][j]);
  for (int i = 1; i <= 100; i++)
    if (s[i]) {
      int t = query(i);
      for (int x = 0; x != s[i]; x++)
        for (int j = 0; j < t - 1 - x; j++)
          ans = sub(ans, dp[i + 1][j]);
    }
  if (!s[0])
    for (int i = 1; i <= 100; i++)
      if (s[i]) {
        if (query(i) > 1)
          ans = add(ans, 1);
        break;
      }
  cout << ans;
}
0