This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define f first
#define s second
#define fast_izho ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
#define m_p make_pair
//#pragma GCC optimize ("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<long long,int> pli;
typedef pair<int,int> pii;
template <class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template <class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const int N=1e6+1;
int ans[N];
void solve(int n,int m){
if(n<0) return;
int v=-1;
for(int j=m;j<=m+n;j++){
if((n&j)==n){
v=j;
break;
}
}
int l=v+1;
while(v>=m){
ans[n--]=v;
--v;
}
solve(n,l);
}
signed main(){
fast_izho;
int n,m;
cin>>n>>m;
int x=31-__builtin_clz(n);
if(pw(x)<n) ++x;
solve(n-1,m);
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... |