結果
| 問題 |
No.3075 Mex Recurrence Formula
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2025-03-29 22:20:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 100 ms / 2,000 ms |
| コード長 | 747 bytes |
| コンパイル時間 | 3,657 ms |
| コンパイル使用メモリ | 282,620 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2025-03-29 22:20:33 |
| 合計ジャッジ時間 | 10,404 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,x;
cin>>n>>x;
V<ll> A(n),B(n+1);
rep(i,n){
cin>>A[i];
if(A[i]<=n) B[A[i]]++;
}
x--;
set<ll> s;
rep(i,n+1) if(B[i]==0) s.insert(i);
if(x<n){
cout<<A[x]<<endl;
return 0;
}
V<ll> C(n+1);
rep(i,n){
auto p=*s.begin();
s.erase(p);
B[p]++;
C[i]=p;
if(A[i]<=n){
B[A[i]]--;
if(B[A[i]]==0) s.insert(A[i]);
}
}
C[n]=*s.begin();
cout<<C[(x-n)%(n+1)]<<endl;
return 0;
}
umezo