#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>> ans;
void swapA(int i,int j){
ans.push_back(make_pair(j,i));
ans.push_back(make_pair(i,j));
ans.push_back(make_pair(j,i));
}
void binaryPrint(int n, int log=6){
for(int i=log-1;i>=0;i--){
if(n&1){
cout<<"1";
}else{
cout<<"0";
}
n>>=1;
}
cout<<endl;
}
#define debug for(int i = 0 ; i < n ; i++)binaryPrint(nums[i]);cout<<endl;
int main(){
int n,s;cin>>n>>s;
vector<int> nums(n);
for(int i = 0 ; i <n;i++){
cin>>nums[i];
}
if(s==1){
for(int pos=0;pos<n;pos++){
for(int i=0;i<n-1;i++){
if(nums[i]>nums[i+1]){
swap(nums[i],nums[i+1]);
swapA(i,i+1);
}
}
}
}else{
//s==2
int last=n;
for(int BIT=19;BIT>=0;BIT--){
int ID=-1;
for(int i=0;i<last;i++){
if((nums[i]>>BIT)&1){
ID=i;
break;
}
}
if(ID==-1)continue;
for(int i=ID;i<last-1;i++){
if(!((nums[i+1]>>BIT)&1)){
ans.push_back(make_pair(i+1,i));
nums[i+1]=nums[i+1]^nums[i];
}
}
for(int i=ID;i>0;i--){
if(!((nums[i-1]>>BIT)&1)){
ans.push_back(make_pair(i-1,i));
nums[i-1]=nums[i-1]^nums[i];
}
}
//On détruit tout les bits sauf 1
for(int i=1;i<last;i++){
// ans i i+1
ans.push_back(make_pair(i-1,i));
nums[i-1]=nums[i-1]^nums[i];
}
last--;
}
}
cout<<ans.size()<<endl;
for(auto&p:ans){
cout<<p.first+1<<' '<<p.second+1<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
16 ms |
596 KB |
Output is correct |
5 |
Correct |
19 ms |
688 KB |
Output is correct |
6 |
Correct |
18 ms |
680 KB |
Output is correct |
7 |
Correct |
18 ms |
688 KB |
Output is correct |
8 |
Correct |
18 ms |
596 KB |
Output is correct |
9 |
Correct |
20 ms |
628 KB |
Output is correct |
10 |
Correct |
25 ms |
644 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
42 ms |
988 KB |
Output is correct |
13 |
Correct |
46 ms |
876 KB |
Output is correct |
14 |
Correct |
35 ms |
848 KB |
Output is correct |
15 |
Correct |
35 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
16 ms |
596 KB |
Output is correct |
5 |
Correct |
19 ms |
688 KB |
Output is correct |
6 |
Correct |
18 ms |
680 KB |
Output is correct |
7 |
Correct |
18 ms |
688 KB |
Output is correct |
8 |
Correct |
18 ms |
596 KB |
Output is correct |
9 |
Correct |
20 ms |
628 KB |
Output is correct |
10 |
Correct |
25 ms |
644 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
42 ms |
988 KB |
Output is correct |
13 |
Correct |
46 ms |
876 KB |
Output is correct |
14 |
Correct |
35 ms |
848 KB |
Output is correct |
15 |
Correct |
35 ms |
852 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
19 ms |
688 KB |
Output is correct |
18 |
Correct |
34 ms |
760 KB |
Output is correct |
19 |
Correct |
39 ms |
856 KB |
Output is correct |
20 |
Correct |
31 ms |
764 KB |
Output is correct |
21 |
Correct |
43 ms |
840 KB |
Output is correct |
22 |
Correct |
33 ms |
816 KB |
Output is correct |
23 |
Correct |
33 ms |
836 KB |
Output is correct |
24 |
Correct |
31 ms |
840 KB |
Output is correct |
25 |
Correct |
31 ms |
748 KB |
Output is correct |
26 |
Incorrect |
77 ms |
1244 KB |
Integer 59568 violates the range [0, 40000] |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
304 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
32 ms |
828 KB |
Output is correct |
6 |
Correct |
36 ms |
904 KB |
Output is correct |
7 |
Correct |
32 ms |
892 KB |
Output is correct |
8 |
Correct |
32 ms |
860 KB |
Output is correct |
9 |
Correct |
39 ms |
804 KB |
Output is correct |
10 |
Correct |
31 ms |
840 KB |
Output is correct |
11 |
Correct |
35 ms |
904 KB |
Output is correct |
12 |
Correct |
42 ms |
912 KB |
Output is correct |
13 |
Correct |
35 ms |
840 KB |
Output is correct |
14 |
Correct |
36 ms |
852 KB |
Output is correct |
15 |
Correct |
55 ms |
980 KB |
Output is correct |