Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AGC 012 C
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
if(p) cout << fixed << setprecision(p) << a << "\n";
else cout << a << "\n";
}
// end of template
template <typename T> inline void voutput(T &v){
rep(i, v.size()){
if (i) cout << " " << v[i];
else cout << v[i];
}
cout << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
// source code
ll N;
cin >> N;
vector<int> ans;
int cur = 1;
while(N >= (1LL << (cur + 1)) - 1){
cur++;
}
ll dist = N - (1LL << cur) + 1;
rep(i, cur) ans.pb(i + 1);
rep(i, cur){
if((dist & (1LL << (cur - i - 1))) > 0) ans.pb(cur + i + 1);
}
rep(i, cur){
if((dist & (1LL << i)) > 0) ans.pb(2 * cur - i);
ans.pb(i + 1);
}
output(ans.size());
voutput(ans);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment