QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#642218#7757. Palm IslandAuroraKelseyTL 0ms0kbC++141.0kb2024-10-15 11:54:352024-10-15 11:54:36

Judging History

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

  • [2024-10-15 11:54:36]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-15 11:54:35]
  • 提交

answer

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


using namespace std;

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


    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:

221
21212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121212121...

result: