結果
| 問題 |
No.3075 Mex Recurrence Formula
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2025-03-28 22:23:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 949 bytes |
| コンパイル時間 | 3,503 ms |
| コンパイル使用メモリ | 285,144 KB |
| 実行使用メモリ | 15,872 KB |
| 最終ジャッジ日時 | 2025-03-28 22:24:07 |
| 合計ジャッジ時間 | 8,181 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 RE * 10 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/modint>
using namespace std;
//using namespace atcoder;
using ll = long long;
//using mint = modint998244353;
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
/*
実験してみたらN+1の周期を持ってそう。
*/
ll N, X;
cin >> N >> X;
deque<ll> v(N);
for (int i=0; i<N; i++) cin >> v[i];
if (X <= N){
cout << v[X-1] << endl;
return 0;
}
X = (X-N-1) % (N+1) + 1;
set<ll> st;
vector<ll> cnt(N+2);
for (int i=0; i<N; i++) cnt[v[i]]++;
for (int i=0; i<=N+1; i++) if (cnt[i] == 0) st.insert(i);
ll ans = -1;
for (int i=1; i<=X; i++){
ans = *st.begin();
cnt[v[0]]--;
if (cnt[v[0]] == 0) st.insert(v[0]);
cnt[ans]++;
if (cnt[ans] == 1) st.erase(ans);
v.pop_front();
v.push_back(ans);
}
cout << ans << endl;
return 0;
}
srjywrdnprkt