結果

問題 No.566 だいたい完全二分木
ユーザー ixmelixmel
提出日時 2017-03-26 16:01:37
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 11:03:34
合計ジャッジ時間 2,657 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1ll<<60;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vi out;
int n,t,q,N;
void dfs(int a,int b){
	if(b+q<=N)out.pb(b+q);
	if(a){
		dfs(a-1,b-pow(2,a-1));
		dfs(a-1,b+pow(2,a-1));
	}
}
int main(){
	cin>>n;
	assert(2<=n&&n<=12);
	q=3*n+1;
	N=pow(2,n);
	if(n<=3){
		rep(i,pow(2,n)-1)cout<<i+1<<" ";
		cout<<pow(2,n)<<endl;
	}else{
		rep(i,3*n+1)out.pb(3*n+1-i);
		t=pow(2,n)-3*n-1;
		rep(i,13)if(t<=pow(2,i)){
			n=i;
			break;
		}
		n++;
		dfs(n-1,pow(2,n-1));
		int m=out.size();
		rep(i,out.size()-1)cout<<out[i]<<" ";cout<<out[m-1]<<endl;
	}
}







0