Submission #9439052


Source Code Expand

Copy
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
#define mem(x,val) memset(x,val,sizeof x)
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
    template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
    bool IN(ll x,ll l,ll r){return l<=x and x<=r;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    set<int> a;typedef set<int>::iterator IT;
    int n,b[N],ban[N];
    bool dfs(int lst)
    {
        if(!sz(a)) return 1;
        for(IT it=a.begin();it!=a.end();)
        {
            int nxt=*it;if(nxt==ban[lst]) {++it;continue;}
            b[n-sz(a)+1]=nxt;a.erase(nxt);
            if(dfs(nxt)) return 1;
            it=a.upper_bound(nxt);a.insert(nxt);
        }return 0;
    }
    void main()
	{
        n=qread();fo(i,1,n) a.insert(i),ban[i]=qread();
        if(!dfs(0)) puts("-1"); else fo(i,1,n) write1(b[i]);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

Submission Info

Submission Time
Task D - Arrangement
User Zory
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2309 Byte
Status
Exec Time 2656 ms
Memory 13952 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 0 / 800 hand2_01, hand2_02, hand2_03, hand2_04, hand_01, hand_02, hand_03, hand_04, handmaid_01, max_01, max_02, max_03, max_04, max_05, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, sample_01, sample_02, sample_03, small_01, small_02, small_03, small_04, small_05, special2_01, special2_02, special2_03, special2_04, special2_05, special2_06, special2_07, special2_08, special2_09, special2_10, special_01, special_02, special_03
Case Name Status Exec Time Memory
hand2_01 1 ms 256 KB
hand2_02 1 ms 256 KB
hand2_03 2656 ms 11904 KB
hand2_04 2656 ms 11904 KB
hand_01 1 ms 256 KB
hand_02 1 ms 256 KB
hand_03 41 ms 12544 KB
hand_04 39 ms 12544 KB
handmaid_01 1 ms 256 KB
max_01 39 ms 12544 KB
max_02 40 ms 12544 KB
max_03 39 ms 12544 KB
max_04 39 ms 12544 KB
max_05 39 ms 12544 KB
random_01 1 ms 256 KB
random_02 1 ms 256 KB
random_03 1 ms 256 KB
random_04 1 ms 256 KB
random_05 1 ms 256 KB
random_06 1 ms 256 KB
random_07 1 ms 256 KB
random_08 1 ms 256 KB
random_09 1 ms 256 KB
random_10 1 ms 256 KB
random_11 1 ms 256 KB
random_12 1 ms 256 KB
random_13 1 ms 256 KB
random_14 1 ms 256 KB
random_15 1 ms 256 KB
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB
small_01 1 ms 256 KB
small_02 1 ms 256 KB
small_03 1 ms 256 KB
small_04 1 ms 256 KB
small_05 1 ms 256 KB
special2_01 2656 ms 13952 KB
special2_02 2656 ms 11904 KB
special2_03 2656 ms 11904 KB
special2_04 2656 ms 11904 KB
special2_05 2656 ms 11904 KB
special2_06 2656 ms 11904 KB
special2_07 2656 ms 11904 KB
special2_08 2656 ms 11904 KB
special2_09 2656 ms 11904 KB
special2_10 2656 ms 11904 KB
special_01 75 ms 256 KB
special_02 76 ms 896 KB
special_03 114 ms 12544 KB