QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627638#7757. Palm Island53DawnsTL 0ms0kbC++202.4kb2024-10-10 16:34:392024-10-10 16:34:39

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 16:34:39]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-10 16:34:39]
  • 提交

answer

#include <bits/stdc++.h>
// #include <bits/extc++.h>
#pragma GCC optimize (1)
#pragma GCC optimize (2)
#pragma GCC optimize (3)
// #define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0)

// using namespace __gnu_pbds;
using namespace std;

const int N=2e5+10,M=1e6+10,mod=1e9+7;

vector<int>ans;
deque<array<int,5>>d;
deque<int>c;


int L[N],R[N];

inline void f2(){
    if(d.size()<=1) return;
    auto x=d[0];
    d.pop_front();
    int s=d[0][2];
    while(s--){
        ans.push_back(2);
    }
    d.push_back(d[0]);
    d.pop_front();
    d.push_front(x);
}

inline int check(){
    if(d.size()<=1) return 0;
    return d[0][1]==d[1][3];
}

void sol(int cases) {
    int n;
    cin>>n;

    c.clear();
    d.clear();
    ans.clear();

    vector<int>a(n+1),b(n+1);

    for(int i=1;i<=n;++i){
        cin>>a[i];
        c.push_back(a[i]);
    }

    for(int i=1;i<=n;++i){
        cin>>b[i];
    }

    for(int i=1;i<=n;++i){
        if(i==1){
            L[b[i]]=b[n];
            R[b[i]]=b[i+1];
        }else if(i==n){
            L[b[i]]=b[i-1];
            R[b[i]]=b[1];
        }else{
            L[b[i]]=b[i-1];
            R[b[i]]=b[i+1];
        }
    }


    for(int i=1;i<=n;++i){
        d.push_back({L[a[i]],R[a[i]],1,a[i],a[i]});
    }

    while(d.size()>1){
        int k=d.size();
        while(d[0][1]!=d[1][3]){
            f2();
        }
        while(check()){
            auto x=d[0];
            d.pop_front();
            auto y=d[0];
            d.pop_front();
            d.push_front({x[0],y[1],x[2]+y[2],x[3],y[4]});
        }

        int s=d[0][2];
        while(s--){
            ans.push_back(1);
        }
        while(d.size()>1&&d[0][2]!=1){
            d.push_back(d[0]);
            d.pop_front();
        }
    }

    for(auto x:ans){
        if(x==1){
            c.push_back(c[0]);
            c.pop_front();
        }else{
            auto &y=c[0];
            c.pop_front();
            c.push_back(c[0]);
            c.pop_front();
            c.push_front(y);
        }
    }
    while(c[0]!=b[1]){
        c.push_back(c[0]);
        c.pop_front();
        ans.push_back(1);
    }

    for(auto &x:ans) cout<<x;
    cout<<'\n';
}

signed main(){
    IOS;
    int t=1;
    // cin>>t;
    for(int i=1;i<=t;++i){
        sol(i);
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

2
3
1 2 3
2 3 1
4
1 2 3 4
2 1 3 4

output:


result: