結果
| 問題 |
No.1963 Subset Mex
|
| コンテスト | |
| ユーザー |
RiverHamster
|
| 提出日時 | 2022-07-13 01:19:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 4,000 ms |
| コード長 | 2,329 bytes |
| コンパイル時間 | 397 ms |
| コンパイル使用メモリ | 57,008 KB |
| 最終ジャッジ日時 | 2025-01-30 06:49:12 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d", &x), ++a[x];
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define LOG(f...) fprintf(stderr, f)
// #define DBG(f...) printf(f)
#define DBG(f...) void()
#define all(cont) begin(cont), end(cont)
const int N = 105;
const int M = 998244353;
void inc(int &x, int y) { if ((x += y) >= M) x -= M; }
int a[N];
int dp[2][N][N];
int cost[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0, x; i < n; ++i)
scanf("%d", &x), ++a[x];
int (*f)[N] = dp[0], (*g)[N] = dp[1];
f[0][0] = 1;
int ans = (a[0] != n) + n, les = n;
for (int i = 100; i; --i, swap(f, g)) {
DBG("i = %d\n", i);
memset(g, 0, sizeof(dp[0]));
les -= a[i];
for (int req = 0, li = n / (i + 1); req <= li; ++req)
for (int cnt = 0, li = a[i] + n / i; cnt <= li; ++cnt) {
auto tf = [&](int r, int e, int val) {
if (r <= n && e <= n) inc(g[r][e], val);
};
int c = req + cnt;
if (c <= a[i]) {
for (int ext = 0; ext <= n; ++ext)
tf(req, ext + a[i] - c, f[req][ext]);
}
else {
for (int ext = 0; ext <= n; ++ext)
tf(req + c - a[i], ext, f[req][ext]);
}
}
for (int c = 1; c <= a[i]; ++c)
for (int ext = 0; ext <= n; ++ext) {
int e = ext + a[i] - c;
int c0 = e + 1 + a[0], req = 1;
for (int j = i - 1; j; --j) {
if (a[j] >= req)
c0 += a[j] - req;
else
req += req - a[j];
if (req > n) break;
}
DBG("e = %d : %d * %d\n", e, f[0][ext], e + les + (req <= c0));
DBG("req = %d c0 = %d\n", req, c0);
ans = (ans + (ll)f[0][ext] * (e + les + (req <= c0))) % M;
if (!ext && les == a[0] && c == a[i] && (les || (req <= c0 && !a[0])))
ans = (ans + M - 1) % M;
}
for (int req = 0; req <= n; ++req)
for (int ext = 0; ext <= n; ++ext)
if (g[req][ext]) DBG("g[%d][%d] = %d\n", req, ext, g[req][ext]);
DBG("ans = %d\n", ans);
}
for (int req = 1; req <= n; ++req)
for (int ext = max(0, req - a[0]); ext <= n; ++ext)
ans = (ans + (ll)f[req][ext] * (ext + a[0] - req + 1)) % M;
printf("%d\n", ans);
}
RiverHamster