#include "bits/stdc++.h"
#define pb push_back
#define int long long
using namespace std;
const int inf = 1e15;
const int N = 1e6 + 5;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin>>n>>m;
vector<int> ans(n);
for(int i = 0; i < n; i++){
ans[i] = i;
}
for(int i = 0; i < 21; i++){
int bt = (1 << i);
vector<int> updans = ans;
vector<int> type[2][2];
for(int j = 0; j < n; j++){
type[(j&bt) > 0][(updans[j]&bt) > 0].pb(j);
}
if((m&bt)){
int ind = 0;
for(auto itr: type[1][1]){
swap(updans[itr], updans[type[0][0][ind]]);
ind++;
}
for(int j = 0; j < n; j++){
updans[j] += bt;
}
}
else{
for(int j = 0; j < n; j++){
int a = ((j&bt) > 0);
int b = ((updans[j]&bt) > 0);
if(!a) continue;
if(a == 1 && b == 0){
for(int k = 0; k < j; k++){
if((j & k) != k) continue;
int ain = (((j - k)&bt) > 0);
int bin = ((updans[j - k]&bt) > 0);
if(ain == 0 && bin == 1){
swap(updans[j], updans[j - k]);
break;
}
}
}
}
}
swap(updans, ans);
}
for(int i = 0; i < n; i++){
cout<<i<<" "<<ans[i]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |