Submission #76334629


Source Code Expand

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define VI vector<int>
#define VII vector<pii>
#define VL vector<ll>
#define VLL vector<pll>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)

#define LOCAL true

using namespace std;
bool st;
const bool MUL=false;

namespace IO{
struct I{
    static constexpr int S=1<<20;
    char b[S],*l=b,*r=b;
    char gc(){return l==r&&(r=(l=b)+fread(b,1,S,stdin),l==r)?EOF:*l++;}
    template<class T>I& operator>>(T&x){
        x=0;int f=1;char c=gc();
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc();}
        while('0'<=c&&c<='9')x=x*10+c-48,c=gc();
        return x*=f,*this;
    }
}in;
struct O{
    static constexpr int S=1<<20;
    char b[S];int p=0;
    ~O(){fwrite(b,1,p,stdout);}
    void pc(char c){if(p==S)fwrite(b,1,p,stdout),p=0;b[p++]=c;}
    template<class T>O& operator<<(T x){
        if(!x)return pc('0'),*this;
        if(x<0)pc('-'),x=-x;
        char s[24];int t=0;
        while(x)s[t++]=x%10+48,x/=10;
        while(t)pc(s[--t]);
        return *this;
    }
    O& operator<<(char c){return pc(c),*this;}
    O& operator<<(const char*s){while(*s)pc(*s++);return *this;}
}out;
}
using IO::in;
using IO::out;

void clr(){
	return;
}
void solve(){
	int n; in>>n; VI ans((1<<n)+10,0); ans[1]=1;
	rep(i,2,n) per(j,(1<<(i-1))-1,1) {
		int u=j+(1<<__lg(j)),v=j+(1<<(__lg(j)+1));
		ans[u]=ans[j]+1,ans[v]=ans[j]+(1<<(i-1))-1;
		if(j==1) ans[v]=(1<<i)-1;
		if(j>=(1<<(i-2))) swap(ans[u],ans[v]);
	}
	rep(i,1,(1<<n)-1) out<<ans[i]<<" \n"[i==(1<<n)-1];
	return; 
}

bool ed;
signed main(){
	int tc=1;if(MUL){in>>tc;}while(tc--)clr(),solve();
	cerr<<"time:"<<clock()<<"ms.\n";
	cerr<<fixed<<setprecision(4)<<"memory:"<<(1.0*(&st-&ed)/1048576.0)<<"MB.\n";
	return 0;
}

Submission Info

Submission Time
Task D - Two Balanced Subtrees
User Fourier_WJY
Language C++23 (GCC 15.2.0)
Score 800
Code Size 1962 Byte
Status AC
Exec Time 5 ms
Memory 5200 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 1
AC × 17
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3772 KiB
01_test_00.txt AC 1 ms 3816 KiB
01_test_01.txt AC 1 ms 3800 KiB
01_test_02.txt AC 1 ms 3772 KiB
01_test_03.txt AC 1 ms 3804 KiB
01_test_04.txt AC 1 ms 3724 KiB
01_test_05.txt AC 1 ms 3792 KiB
01_test_06.txt AC 1 ms 3816 KiB
01_test_07.txt AC 1 ms 3600 KiB
01_test_08.txt AC 1 ms 3768 KiB
01_test_09.txt AC 1 ms 3932 KiB
01_test_10.txt AC 1 ms 3900 KiB
01_test_11.txt AC 1 ms 3864 KiB
01_test_12.txt AC 2 ms 4152 KiB
01_test_13.txt AC 2 ms 4276 KiB
01_test_14.txt AC 3 ms 4608 KiB
01_test_15.txt AC 5 ms 5200 KiB