#include <bits/stdc++.h>
using namespace std;
int n, s, a[1000];
vector<pair<int, int> > res;
int main() {
cin>>n>>s;
for(int i = 0; i < n; i++)
cin>>a[i];
for(int i = 0; i < n; i++) {
int m = i;
for(int j = i + 1; j < n; j++)
if(a[m] > a[j])
m = j;
for(int j = m; j > i; j--) {
res.push_back({j, j - 1});
res.push_back({j - 1, j});
if(s == 1) {
res.push_back({j, j - 1});
swap(a[j - 1], a[j]);
} else {
a[j] ^= a[j - 1];
a[j - 1] ^= a[j];
}
}
}
cout<<res.size()<<'\n';
for(auto i : res)
cout<<i.first + 1<<" "<<i.second + 1<<'\n';
//for(int i = 0; i < n; i++)
// cout<<a[i]<<" ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
820 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
3 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
984 KB |
Output is correct |
13 |
Correct |
6 ms |
984 KB |
Output is correct |
14 |
Correct |
4 ms |
1008 KB |
Output is correct |
15 |
Correct |
4 ms |
984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
820 KB |
Output is correct |
6 |
Correct |
2 ms |
728 KB |
Output is correct |
7 |
Correct |
3 ms |
728 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
3 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
4 ms |
984 KB |
Output is correct |
13 |
Correct |
6 ms |
984 KB |
Output is correct |
14 |
Correct |
4 ms |
1008 KB |
Output is correct |
15 |
Correct |
4 ms |
984 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
4 ms |
984 KB |
Output is correct |
19 |
Correct |
4 ms |
984 KB |
Output is correct |
20 |
Correct |
4 ms |
984 KB |
Output is correct |
21 |
Correct |
4 ms |
984 KB |
Output is correct |
22 |
Correct |
4 ms |
984 KB |
Output is correct |
23 |
Correct |
4 ms |
984 KB |
Output is correct |
24 |
Correct |
4 ms |
984 KB |
Output is correct |
25 |
Correct |
3 ms |
984 KB |
Output is correct |
26 |
Incorrect |
7 ms |
1488 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
444 KB |
Not sorted |
3 |
Halted |
0 ms |
0 KB |
- |