#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n;
cin >> n;
bool arr[n*2];
for(int i = 0;i < n*2;i++){
arr[i] = false;
}
int xx;
cin >> xx;
cout << xx << " ";
arr[xx] = true;
int l = 1;
if(xx == 1) l++;
int r = 2*n-1;
if(xx == r) r--;
int last = xx;
for(int i = 1;i < n;i++){
int x;
cin >> x;
if(x == last){
cout << l << " " << r << " ";
arr[l] = true;
while(arr[l]){
l++;
}
arr[r] = true;
while(arr[r]){
r--;
}
}else if(x > last && !arr[x]){
cout << x << " " << r << " ";
arr[x] = true;
arr[r] = true;
while(arr[r]){
r--;
}
}else if(x > last) {
cout << r << " ";
arr[r] = true;
while(arr[r]){
r--;
}
cout << r << " ";
arr[r] = true;
while(arr[r]){
r--;
}
}else if(x < last && !arr[x]){
cout << x << " " << l << " ";
arr[x] = true;
arr[l] = true;
while(arr[l]){
l++;
}
}else{
cout << l << " ";
arr[l] = true;
while(arr[l]){
l++;
}
cout << l << " ";
arr[l] = true;
while(arr[l]){
l++;
}
}
last = x;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Not a permutation |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Incorrect |
3 ms |
604 KB |
Not a permutation |
5 |
Correct |
6 ms |
860 KB |
Output is correct |
6 |
Incorrect |
12 ms |
1368 KB |
Not a permutation |
7 |
Correct |
19 ms |
1948 KB |
Output is correct |