結果
問題 | No.3075 Mex Recurrence Formula |
ユーザー |
![]() |
提出日時 | 2025-03-28 22:27:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 998 bytes |
コンパイル時間 | 4,058 ms |
コンパイル使用メモリ | 285,536 KB |
実行使用メモリ | 15,872 KB |
最終ジャッジ日時 | 2025-03-28 22:28:01 |
合計ジャッジ時間 | 8,391 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
#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++) if (v[i] <= N+1) 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(); if (v[0] <= N+1) cnt[v[0]]--; if (v[0] <= N+1 && 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; }