QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#655876#7757. Palm IslandanlanyiTL 0ms9204kbC++201.3kb2024-10-19 10:05:442024-10-19 10:05:46

Judging History

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

  • [2024-10-19 10:05:46]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:9204kb
  • [2024-10-19 10:05:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
using ll=long long ;
int a[N],b[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,T;
    cin >> T;
    while(T--){
        cin >> n;
        queue<int >w;
        for(int i=1;i<=n;i++){
            cin >> a[i];
            w.push(a[i]);
        }
        for(int i=1;i<=n;i++){
            cin >> b[i];
        }
        vector<vector<int >>vis(1010,vector<int >(1010));
        int cnt=0;
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++){
                if(b[i]>b[j])vis[b[j]][b[i]]=1,cnt++;
            }
        while(cnt){
            int x=w.front();w.pop();
            int y=w.front();w.pop();
            if(vis[x][y]){
                while(vis[x][y]){
                    cout<<21;
                    cnt--;
                    vis[x][y]=0;
                    w.push(y);
                    w.push(x);
                }
            }else {
                cout<<11;
                w.push(x);
                w.push(y);
            }
        }
        while(w.front()!=b[1]){
            cout<<1;
            int t=w.front();
            w.pop();
            w.push(t);
        }
        cout<<'\n';
        

    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

211121
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:

1111211121
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result: