#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define int long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define speed ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define file freopen("palindrome.in", "r", stdin), freopen("palindrome.out", "w", stdout);
const int N = (int) 5 * 1e5, inf = INT_MAX;
int a[2000], b[2000];
main() {
speed;
int n, S;
cin >> n >> S;
vector<pair<int, int>> v;
v.pb({0, 0});
for(int i = 1; i <= n; i++){
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + 1 + n);
for(int i = n; i >= 1; i--){
if(b[i] == a[i]){
continue;
}
int x;
for(int j = 1; j <= n; j++){
if(a[j] == b[i]){
x = j;
break;
}
}
while(x != i){
v.pb({x + 1, x});
v.pb({x, x + 1});
v.pb({x + 1, x});
swap(a[x], a[x + 1]);
x++;
}
}
cout << v.size() - 1 << "\n";
for(int i = 1; i < v.size(); i++){
cout << v[i].F << " " << v[i].S << '\n';
}
}
Compilation message
xorsort.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main() {
| ^~~~
xorsort.cpp: In function 'int main()':
xorsort.cpp:44:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i = 1; i < v.size(); i++){
| ~~^~~~~~~~~~
xorsort.cpp:28:10: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | int x;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
968 KB |
Output is correct |
6 |
Correct |
3 ms |
984 KB |
Output is correct |
7 |
Correct |
3 ms |
984 KB |
Output is correct |
8 |
Correct |
4 ms |
968 KB |
Output is correct |
9 |
Correct |
3 ms |
984 KB |
Output is correct |
10 |
Correct |
3 ms |
984 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
1492 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
6 ms |
1492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
968 KB |
Output is correct |
6 |
Correct |
3 ms |
984 KB |
Output is correct |
7 |
Correct |
3 ms |
984 KB |
Output is correct |
8 |
Correct |
4 ms |
968 KB |
Output is correct |
9 |
Correct |
3 ms |
984 KB |
Output is correct |
10 |
Correct |
3 ms |
984 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
5 ms |
1492 KB |
Output is correct |
13 |
Correct |
5 ms |
1492 KB |
Output is correct |
14 |
Correct |
5 ms |
1492 KB |
Output is correct |
15 |
Correct |
6 ms |
1492 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
984 KB |
Output is correct |
18 |
Correct |
4 ms |
1108 KB |
Output is correct |
19 |
Correct |
4 ms |
1108 KB |
Output is correct |
20 |
Correct |
4 ms |
1084 KB |
Output is correct |
21 |
Correct |
4 ms |
1140 KB |
Output is correct |
22 |
Correct |
5 ms |
1108 KB |
Output is correct |
23 |
Correct |
5 ms |
1108 KB |
Output is correct |
24 |
Correct |
4 ms |
1108 KB |
Output is correct |
25 |
Correct |
4 ms |
1108 KB |
Output is correct |
26 |
Incorrect |
8 ms |
1752 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Incorrect |
105 ms |
18432 KB |
Integer 764742 violates the range [0, 40000] |
6 |
Halted |
0 ms |
0 KB |
- |