結果

問題 No.2740 Old Maid
ユーザー capy-capycapy-capy
提出日時 2024-04-21 15:48:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 2,286 ms
コンパイル使用メモリ 174,828 KB
実行使用メモリ 10,012 KB
最終ジャッジ日時 2024-04-21 15:48:51
合計ジャッジ時間 9,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
9,760 KB
testcase_01 AC 115 ms
9,756 KB
testcase_02 AC 114 ms
9,700 KB
testcase_03 AC 116 ms
9,756 KB
testcase_04 AC 114 ms
10,012 KB
testcase_05 AC 116 ms
9,836 KB
testcase_06 AC 114 ms
9,752 KB
testcase_07 AC 114 ms
9,884 KB
testcase_08 AC 114 ms
9,884 KB
testcase_09 AC 114 ms
9,884 KB
testcase_10 AC 112 ms
9,760 KB
testcase_11 AC 112 ms
9,756 KB
testcase_12 AC 89 ms
8,152 KB
testcase_13 AC 99 ms
8,332 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 66 ms
6,772 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 AC 91 ms
8,232 KB
testcase_19 AC 37 ms
5,376 KB
testcase_20 AC 107 ms
8,868 KB
testcase_21 AC 23 ms
5,376 KB
testcase_22 AC 64 ms
6,712 KB
testcase_23 AC 15 ms
5,376 KB
testcase_24 AC 35 ms
5,376 KB
testcase_25 AC 114 ms
9,272 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 10 ms
5,376 KB
testcase_28 AC 67 ms
6,628 KB
testcase_29 AC 63 ms
6,540 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 134 ms
9,568 KB
testcase_32 AC 43 ms
5,768 KB
testcase_33 AC 124 ms
9,392 KB
testcase_34 AC 61 ms
6,516 KB
testcase_35 AC 37 ms
5,376 KB
testcase_36 AC 37 ms
5,376 KB
testcase_37 AC 51 ms
5,992 KB
testcase_38 AC 31 ms
5,376 KB
testcase_39 AC 18 ms
5,376 KB
testcase_40 AC 79 ms
7,196 KB
testcase_41 AC 106 ms
8,968 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #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;
}
0