結果
| 問題 | No.3780 Erase and Mex |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-10-30 21:39:53 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 17 ms / 2,000 ms |
| + 547µs | |
| コード長 | 1,518 bytes |
| 記録 | |
| コンパイル時間 | 2,748 ms |
| コンパイル使用メモリ | 362,240 KB |
| 実行使用メモリ | 9,864 KB |
| 最終ジャッジ日時 | 2026-10-30 21:40:01 |
| 合計ジャッジ時間 | 6,993 ms |
|
ジャッジサーバーID (参考情報) |
judge7_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
VI a(n);
rep(i, n) cin >> a[i];
if (n == 1) {
cout << max(a[0], 1) << '\n';
continue;
}
VI freq(n + 1);
for (int x : a) {
if (x < n) freq[x]++;
else freq[0]++;
}
int l = 0, r = n + 1;
while (r - l > 1) {
int c = (l + r) / 2;
auto f = freq;
for (int i = c; i <= n; i++) f[0] += f[i], f[i] = 0;
int req = 1;
for (int i = c - 1; i >= 1; i--) {
int t = min(req, f[i]);
int rest = req - t;
req += rest;
f[0] += f[i] - t;
f[i] = 0;
if (req > n) break;
}
(req <= f[0] ? l : r) = c;
}
cout << l << '\n';
}
}
Kude