結果

問題 No.1051 PQ Permutation
ユーザー auauaauaua
提出日時 2020-05-08 23:20:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,746 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 175,068 KB
実行使用メモリ 16,180 KB
最終ジャッジ日時 2023-09-19 08:08:24
合計ジャッジ時間 7,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 158 ms
15,608 KB
testcase_16 AC 169 ms
15,600 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 228 ms
16,024 KB
testcase_21 AC 224 ms
15,960 KB
testcase_22 WA -
testcase_23 AC 225 ms
16,024 KB
testcase_24 AC 231 ms
16,172 KB
testcase_25 AC 13 ms
4,384 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 69 ms
8,700 KB
testcase_37 AC 138 ms
13,760 KB
testcase_38 WA -
testcase_39 AC 140 ms
15,504 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 139 ms
13,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n,p,q;cin>>n>>p>>q;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    set<ll>st;
    vector<ll>b(0);
    rep(i,n){
        st.insert(i+1);
    }
    ll cnt=0;
    st.erase(p);
    st.erase(q);
    bool d=0;
    rep(i,n){
        if(d){
            auto itr=st.lower_bound(0);
            if(itr==st.end()){
                if(cnt==0){
                    b.pb(p);
                    cnt++;
                }else if(cnt==1){
                    b.pb(q);
                    cnt++;
                }
            }else{
            if(cnt==0){
                if(p<*itr){
                    b.pb(p);
                    cnt++;
                }else{

                    b.pb(*itr);
                    st.erase(*itr);
                }
            }else if(cnt==1){
                if(q<*itr){
                    b.pb(q);
                    cnt++;
                }else{
                    b.pb(*itr);
                    st.erase(*itr);
                }
            }else{
                b.pb(*itr);
                st.erase(*itr);
            }
            }
            continue;
        }
        auto itr=st.lower_bound(a[i]);
        if(itr==st.end()){
            if(cnt==0){
                b.pb(p);
                cnt++;
            }else if(cnt==1){
                b.pb(q);
                cnt++;
            }
        }else{
        if(cnt==1){
            if(q>=a[i]&&q<*itr){
                b.pb(q);
                cnt++;
            }else{
                b.pb(*itr);
                st.erase(*itr);
            }
        }else if(cnt==0){
            if(p>=a[i]&&p<*itr){
                b.pb(p);
                cnt++;
            }else{
                b.pb(*itr);
                st.erase(*itr);
            }
        }else{
            b.pb(*itr);
            st.erase(*itr);
        }
        }
        if(b[i]>a[i])d=1;
    }
    bool f=1;
    if(b.size()<n){
        f=0;
    }else{
        bool k=0;
        rep(i,n){
            if(a[i]<b[i]){
                k=1;
                break;
            }
            if(a[i]>b[i]){
                k=0;
                break;
            }
        }
        f&=k;
    }
    if(f){
        rep(i,n){
            cout<<b[i]<<' ';
        }
        cout<<endl;
    }else{
        cout<<-1<<endl;
    }
}
0