結果

問題 No.2740 Old Maid
ユーザー 0214sh70214sh7
提出日時 2024-04-21 02:07:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,625 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 205,348 KB
実行使用メモリ 23,848 KB
最終ジャッジ日時 2024-04-21 02:07:41
合計ジャッジ時間 10,343 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
22,016 KB
testcase_01 AC 161 ms
22,016 KB
testcase_02 AC 166 ms
22,016 KB
testcase_03 AC 168 ms
22,016 KB
testcase_04 AC 164 ms
22,016 KB
testcase_05 AC 163 ms
22,144 KB
testcase_06 AC 176 ms
22,016 KB
testcase_07 AC 166 ms
22,144 KB
testcase_08 AC 166 ms
22,016 KB
testcase_09 AC 165 ms
22,144 KB
testcase_10 AC 157 ms
22,144 KB
testcase_11 AC 159 ms
22,016 KB
testcase_12 AC 165 ms
18,244 KB
testcase_13 AC 157 ms
19,560 KB
testcase_14 AC 27 ms
6,528 KB
testcase_15 AC 40 ms
7,552 KB
testcase_16 AC 104 ms
14,460 KB
testcase_17 AC 27 ms
6,144 KB
testcase_18 AC 148 ms
18,864 KB
testcase_19 AC 57 ms
9,600 KB
testcase_20 AC 183 ms
21,116 KB
testcase_21 AC 32 ms
7,168 KB
testcase_22 AC 118 ms
14,208 KB
testcase_23 AC 19 ms
5,888 KB
testcase_24 AC 52 ms
9,216 KB
testcase_25 AC 190 ms
22,116 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 14 ms
5,376 KB
testcase_28 AC 102 ms
14,360 KB
testcase_29 AC 96 ms
13,824 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 214 ms
23,848 KB
testcase_32 AC 62 ms
10,744 KB
testcase_33 AC 234 ms
22,808 KB
testcase_34 AC 98 ms
13,712 KB
testcase_35 AC 51 ms
9,088 KB
testcase_36 AC 54 ms
9,600 KB
testcase_37 AC 78 ms
12,124 KB
testcase_38 AC 43 ms
8,448 KB
testcase_39 AC 23 ms
6,144 KB
testcase_40 AC 123 ms
16,308 KB
testcase_41 AC 179 ms
20,916 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 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 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 1 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 1 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PP;
// #define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ORREP(i,n) for(ll i=(n);i>=1;--i)
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false


int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<ll> P(N);
    REP(i,N){cin >> P[i];P[i]--;}
    
    list<ll> L;REP(i,N){L.push_back(P[i]);}
    vector<_List_iterator<long long>> IT(N);
    int now = 0;
    for(auto it=L.begin();it!=L.end();it++){
        IT[P[now]] = it;
        now++;
    }
    
    set<ll> R;
    REP(i,N){R.insert(i);}
    vector<ll> Ans;
    
    REP(i,N/2){
        
        ll z = *R.begin();
        auto it = L.end();it--;
        
        if(z==(*it)){
            
            auto it2 = R.begin();it2++;
            z = *it2;
            
        }
        
        Ans.push_back(*IT[z]);
        R.erase(R.find(*IT[z]));
        auto it3 = L.erase(IT[z]);
        Ans.push_back(*it3);
        R.erase(R.find(*it3));
        L.erase(it3);
        
    }
    
    REP(i,N){
        cout << Ans[i]+1 << " ";
    }
    cout << endl;

    
    return 0;
    
}
0