結果

問題 No.2740 Old Maid
ユーザー MtSakaMtSaka
提出日時 2024-04-20 10:35:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,711 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 204,336 KB
実行使用メモリ 19,260 KB
最終ジャッジ日時 2024-04-20 10:35:17
合計ジャッジ時間 9,223 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
17,536 KB
testcase_01 AC 148 ms
17,280 KB
testcase_02 AC 145 ms
17,408 KB
testcase_03 AC 147 ms
17,280 KB
testcase_04 AC 150 ms
17,408 KB
testcase_05 AC 155 ms
17,280 KB
testcase_06 AC 155 ms
17,408 KB
testcase_07 AC 154 ms
17,280 KB
testcase_08 AC 146 ms
17,280 KB
testcase_09 AC 145 ms
17,536 KB
testcase_10 AC 138 ms
17,408 KB
testcase_11 AC 152 ms
17,408 KB
testcase_12 AC 124 ms
14,208 KB
testcase_13 AC 136 ms
16,040 KB
testcase_14 AC 25 ms
6,944 KB
testcase_15 AC 33 ms
6,940 KB
testcase_16 AC 90 ms
11,664 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 129 ms
14,464 KB
testcase_19 AC 46 ms
7,680 KB
testcase_20 AC 156 ms
17,300 KB
testcase_21 AC 29 ms
6,940 KB
testcase_22 AC 87 ms
11,648 KB
testcase_23 AC 17 ms
6,940 KB
testcase_24 AC 44 ms
7,680 KB
testcase_25 AC 160 ms
17,824 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 11 ms
6,940 KB
testcase_28 AC 87 ms
11,852 KB
testcase_29 AC 83 ms
11,008 KB
testcase_30 AC 5 ms
6,944 KB
testcase_31 AC 175 ms
19,260 KB
testcase_32 AC 54 ms
8,880 KB
testcase_33 AC 167 ms
18,348 KB
testcase_34 AC 92 ms
11,116 KB
testcase_35 AC 44 ms
7,552 KB
testcase_36 AC 46 ms
7,936 KB
testcase_37 AC 69 ms
9,344 KB
testcase_38 AC 39 ms
7,040 KB
testcase_39 AC 22 ms
6,940 KB
testcase_40 AC 105 ms
13,088 KB
testcase_41 AC 150 ms
17,156 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 1 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 1 ms
6,944 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 1 ms
6,940 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 1 ms
6,944 KB
testcase_64 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define overload(a,b,c,d,...) d
#define rep1(a) for(ll _=0;_<(ll)a;++_)
#define rep2(i,a) for(ll i=0;i<(ll)a;++i)
#define rep3(i,a,b) for(ll i=(ll)a;i<(ll)b;++i)
#define rep(...) overload(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)a-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)b-1;i>=(ll)a;--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define eb emplace_back
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb(v,x) (lower_bound(all(v),x)-(v).begin())
#define ub(v,x) (upper_bound(all(v),x)-(v).begin())
using namespace std;
using ll=long long;
using vl=vector<ll>;
using ld=long double;
using i128=__int128_t;
template<typename T,typename U>inline static constexpr bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline static constexpr bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}
static constexpr ll inf=numeric_limits<ll>::max()/2;
struct IOSetup{IOSetup(){ios::sync_with_stdio(false);cin.tie(nullptr);}};
static constexpr ll mod=998244353;
ll fac(ll n){return (n==0?1:fac(n-1)*n);}
int main(){
    ll n;cin>>n;
    vl p(n);for(auto&&e:p)cin>>e;
    vl nxt(n,-1);
    vl bef(n,-1);
    rep(i,n-1)nxt[p[i]-1]=p[i+1]-1;
    rep(i,n-1)bef[p[i+1]-1]=p[i]-1;
    set<ll>st;
    rep(i,n)st.insert(i);
    vl q;
    rep(i,n/2){
        ll a=*st.begin();
        if(nxt[a]==-1)a=*next(st.begin());
        ll b=nxt[a];
        q.eb(a);
        q.eb(b);
        if(bef[a]!=-1)nxt[bef[a]]=nxt[b];
        if(nxt[b]!=-1)bef[nxt[b]]=bef[a];
        st.erase(a);
        st.erase(b);
    }
    rep(i,n)cout<<q[i]+1<<" \n"[i==n-1];
}
0