結果
| 問題 |
No.1963 Subset Mex
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-02 19:59:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 4,000 ms |
| コード長 | 2,050 bytes |
| コンパイル時間 | 607 ms |
| コンパイル使用メモリ | 68,932 KB |
| 実行使用メモリ | 7,808 KB |
| 最終ジャッジ日時 | 2024-11-27 16:55:59 |
| 合計ジャッジ時間 | 1,993 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#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;
}