結果
| 問題 | No.3780 Erase and Mex |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-10-31 21:06:24 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 22 ms / 2,000 ms |
| + 450µs | |
| コード長 | 1,039 bytes |
| 記録 | |
| コンパイル時間 | 255 ms |
| コンパイル使用メモリ | 58,500 KB |
| 実行使用メモリ | 9,836 KB |
| 最終ジャッジ日時 | 2026-10-31 21:06:32 |
| 合計ジャッジ時間 | 4,196 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge7_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3780.cc: No.3780 Erase and Mex - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
using ll = long long;
/* global variables */
int as[MAX_N], cs[MAX_N + 2];
/* subroutines */
bool check(int n, int x) {
int c0 = cs[0], d = 1;
for (int i = n + 1; i > 0 && d <= n; i--) {
if (i >= x) c0 += cs[i];
else {
int dc = d - cs[i];
if (dc <= 0) c0 += -dc;
else d += dc;
}
}
return c0 >= d;
}
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
if (n == 1) { printf("%d\n", max(1, as[0])); continue; }
fill(cs, cs + n + 2, 0);
for (int i = 0; i < n; i++) cs[min(n + 1, as[i])]++;
int x0 = 0, x1 = n + 1;
while (x0 + 1 < x1) {
int x = (x0 + x1) / 2;
if (check(n, x)) x0 = x;
else x1 = x;
}
printf("%d\n", x0);
}
return 0;
}
tnakao0123