結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-02 00:01:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 183 ms / 2,000 ms |
| コード長 | 738 bytes |
| コンパイル時間 | 2,088 ms |
| コンパイル使用メモリ | 202,116 KB |
| 最終ジャッジ日時 | 2025-02-21 10:06:32 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector P(N,0);
for(int &i:P)cin>>i,--i;
vector idx(N,0);
for(int i=0;i<N;i++){
idx[P[i]]=i;
}
set<int>ok;
for(int i=0;i<N;i++){
ok.insert(i);
}
vector ans(0,0),used(N,0);
for(int i=0;i<N;i++){
if(!used[i]){
auto t=ok.upper_bound(idx[i]);
if(t!=ok.end()){
int k=*t;
ans.push_back(i);
ans.push_back(P[k]);
used[i]=1;
used[P[k]]=1;
ok.erase(idx[i]);
ok.erase(k);
}
}
}
for(int i=0;i<N;i++){
if(i)cout<<' ';
cout<<ans[i]+1;
}
cout<<'\n';
}