QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642171#7757. Palm IslandAuroraKelseyTL 1ms5656kbC++141.1kb2024-10-15 11:25:452024-10-15 11:25:45

Judging History

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

  • [2024-10-15 11:25:45]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5656kb
  • [2024-10-15 11:25:45]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <climits>


using namespace std;

const int N = 1000001;
int n;
int a[N], b[N];
map<int, int> mp;
bool check(int cur) {
    for(int i=1;i<=n;i++) {
        if(cur+i>n) {
            if(a[cur+i-n]!=b[i])
                return 0;
        }else{
            if(a[cur+i]!=b[i])
                return 0;
        }
    }
    return 1;
}
int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 1; i <= n; i++)
            cin>>b[i],mp[b[i]]=i;
        int tmp;
        int i=1,j=2;
        while(1){
            if(i>n) i-=n;
            if(j>n) j-=n;
           if(mp[a[i]]<mp[a[j]]) {
               swap(a[i],a[j]);
               i=j;
               cout<<2;
           }else{
               i++;
               cout<<1;
           }
           j=i+1;
            if(check(i-1))break;
        }
        cout<<"\n";
    }


    return 0;
}


詳細信息

Test #1:

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

input:

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

output:

1
122

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:

212
22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222...

result: