結果
| 問題 | No.3780 Erase and Mex |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-10-31 20:59:12 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,013 bytes |
| 記録 | |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 58,344 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2026-10-31 20:59:21 |
| 合計ジャッジ時間 | 4,549 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 WA * 29 |
ソースコード
/* -*- 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) {
ll c0 = cs[0], d = 1;
for (int i = n + 1; i > 0; i--) {
if (i > x) c0 += cs[i];
else {
if (cs[i] >= d) c0 += cs[i] - d;
else d += d - cs[i];
}
}
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;
while (x0 + 1 < x1) {
int x = (x0 + x1) / 2;
if (check(n, x)) x0 = x;
else x1 = x;
}
printf("%d\n", x1);
}
return 0;
}
tnakao0123