QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473157#7757. Palm IslandyzhangWA 1ms3672kbC++141.1kb2024-07-11 22:37:132024-07-11 22:37:13

Judging History

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

  • [2024-07-11 22:37:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3672kb
  • [2024-07-11 22:37:13]
  • 提交

answer

#include<bits/stdc++.h>
#define N 1005
using namespace std;
int T,n,a[N],b[N],ndp[N];
int pre[N],nxt[N],bg,ed;
void op1(){
    pre[bg]=ed;
    nxt[ed]=bg;
    bg=nxt[bg];
    ed=nxt[ed];
    cout<<"1";
}
void op2(){
    pre[nxt[nxt[bg]]]=bg;
    pre[nxt[bg]]=ed;
    nxt[ed]=nxt[bg];
    ed=nxt[ed];
    nxt[bg]=nxt[nxt[bg]];
    cout<<"2";
}
void print(){
    int cur=bg;
    for(int i=1;i<=n;++i){
        cerr<<cur<<" ";
        cur=nxt[cur];
    }
    cerr<<'\n';
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=1;i<=n;++i) cin>>b[i];
    pre[a[n]]=a[n-1],nxt[a[1]]=a[2];
    bg=a[1],ed=a[n];
    for(int i=2;i<n;++i)
        pre[a[i]]=a[i-1],nxt[a[i]]=a[i+1];
    ndp[b[1]]=b[n];
    for(int i=2;i<=n;++i)
        ndp[b[i]]=b[i-1];
    int cnt=0;
    for(int i=1;i<=n-1;++i){
        while(ndp[nxt[bg]]!=bg) op2();
        op1();
    }
    for(int i=1;i<=n;++i){
        if(bg==b[1]){
            cout<<'\n';
            return;
        }
        op1();
    }
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3672kb

input:

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

output:

1111
2111

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

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
21212111
22111
2221121221
2212122121
111111
11
12121
221111
11
21111
22111
2111
211
11111111
12121
22121211
1111
1111
211212211
12121111
2212121111
2111111
121211
2221221211111
1111
2121221211
12212111111
12121111
211111
2111
22121211
211
221111
2211212211
2221212212111
211
22111
22111111
111
221...

result:

wrong answer On Case#2: After your operations, a[2] = 4 but a[2] = 1. (test case 2)