結果
問題 | No.2740 Old Maid |
ユーザー |
|
提出日時 | 2024-04-21 15:48:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 116 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 1,822 ms |
コンパイル使用メモリ | 180,152 KB |
実行使用メモリ | 9,888 KB |
最終ジャッジ日時 | 2024-10-13 14:43:49 |
合計ジャッジ時間 | 8,313 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
// #pragma GCC target "prefer-vector-width=512"// #pragma GCC optimize "Ofast"#include <bits/stdc++.h>using namespace std;#define ll long long#define rep(i,N) for(int i=0;i<(int)N;i++)#define rrep(i,s,e) for(int i=s;i<(int)e;i++)#define all(x) x.begin(),x.end()#define vecin(N,A) rep(i,N) cin>>A[i]#define vvecin(H,W,A) rep(i,H) rep(j,W) cin>>A[i][j]int main(){int N;cin>>N;vector<int>P(N);vecin(N,P);vector<int>q;priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>Q;vector<pair<int,pair<int,int>>>M(N);vector<bool>seen(N,false);rep(i,N){M[i]={P[i],{i-1,i+1}};}rep(i,N-1){Q.push({P[i],i});}while(!Q.empty()){int val = Q.top().first;int ite = Q.top().second;Q.pop();if(seen[ite])continue;seen[ite]=true;int nit = M[ite].second.second;if(nit>=N)continue;q.push_back(val);q.push_back(M[nit].first);seen[nit]=true;if(M[ite].second.first>=0)M[M[ite].second.first].second.second=M[nit].second.second;if(M[nit].second.second<N)M[M[nit].second.second].second.first=M[ite].second.first;}for(auto e :q)cout<<e<<" ";cout<<endl;}