QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#642218 | #7757. Palm Island | AuroraKelsey | TL | 0ms | 0kb | C++14 | 1.0kb | 2024-10-15 11:54:35 | 2024-10-15 11:54:36 |
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...