QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633179#7757. Palm IslandOrthosTL 0ms3604kbC++171.5kb2024-10-12 14:42:182024-10-12 14:42:19

Judging History

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

  • [2024-10-12 14:42:19]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3604kb
  • [2024-10-12 14:42:18]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
#define inf 1e7
using namespace std;
int t,n;

int a[1005],b[1005];
int ne[1005];
int pre[1005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>t;
    while(t--){
        cin>>n;
        queue<int> q;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            q.push(a[i]);
            pre[a[i]]=1;
        }
        for(int i=1;i<=n;i++){
            cin>>b[i];
        }
        for(int i=1;i<=n;i++){
            ne[b[i]]=b[i+1];
        }
        ne[b[n]]=-1;
        while(1){
            int hd=q.front();
            queue<int> qq=q;
            bool ok=1;
            for(int i=1;i<=n;i++){
                if(qq.front()==b[i]){
                    qq.pop();
                }
                else{
                    ok=0;
                }
            }
            if(ok){
                break;
            }
            q.pop();
            if(ne[hd]==-1){
                q.push(hd);
                cout<<1;
                continue;
            }
            while(q.front()!=ne[hd]){
                int tp=q.front();
                q.pop();
                q.push(tp);
                cout<<"2";
            }
            pre[hd]=pre[q.front()]+1;
            q.push(hd);
            cout<<1;
            for(int i=1;i<pre[hd];i++){
                cout<<1;
                int tp=q.front();
                q.pop();
                q.push(tp);
            }
        }
        cout<<"\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

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

output:

1
2111

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

200
3
3 1 2
2 3 1
4
2 4 1 3
2 1 4 3
4
1 4 2 3
2 1 3 4
5
4 3 2 1 5
2 4 5 3 1
5
2 1 5 4 3
5 2 4 1 3
4
4 3 1 2
1 2 4 3
3
1 2 3
3 1 2
4
1 4 2 3
2 1 4 3
4
1 3 2 4
1 4 3 2
3
3 2 1
1 3 2
3
2 3 1
1 3 2
4
1 4 3 2
3 1 2 4
3
1 2 3
1 3 2
3
3 2 1
2 3 1
5
5 1 3 2 4
2 4 5 1 3
4
4 3 1 2
1 4 3 2
4
1 3 4 2
2 4 3 1
3
...

output:

11
21112211
22111
22211211112211111
2211122211
11
11
1121111
221111
11
1211
22111
2111
211
111
1121111
122112111
1

2112111122111
112111
22112111
211
121112211
22211112211111
1
211211
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result: