QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642158#7757. Palm IslandAuroraKelseyTL 1ms5676kbC++14962b2024-10-15 11:13:082024-10-15 11:13:09

Judging History

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

  • [2024-10-15 11:13:09]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5676kb
  • [2024-10-15 11:13:08]
  • 提交

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() {
    for(int i=1;i<=n;i++)
        if(a[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 j;
        int tmp;
        while(1){
           if(mp[a[1]]<mp[a[2]]) {
               tmp=a[2];
               j=2;
               cout<<2;
           }else{
               tmp=a[1];
               cout<<1;
               j=1;
           }
            for(int i=j;i<n;i++)
                a[i]=a[i+1];
            a[n]=tmp;
            if(check())break;
        }
        cout<<"\n";
    }


    return 0;
}


详细

Test #1:

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

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: