Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661#116. 【0621 模拟赛】OBILAZAKFXLIR1005ms11828kbC++14661b2025-06-21 15:28:482025-06-21 23:51:29

answer

#include<cmath>
#include<iostream>
#define int long long
using namespace std;
const int N=1e5+5,INF=1e9;
int k,n,pw[N],a[N],ans[15][N],tot[15];
void init(){
	pw[0]=1;
	for(int i=1;i<=12;i++){
		pw[i]=pw[i-1]*2;
	}
	return;
}
void dfs(int l,int r,int c){
	ans[c][++tot[c]]=a[(l+r)/2];
	if(l==r){
		return;
	}
	dfs(l,(l+r)/2-1,c+1);
	dfs((l+r)/2+1,r,c+1);
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	init();
	cin>>k;
	n=(int)pow(2,k)-1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfs(1,n,1);
	for(int i=1;i<=k;i++){
		for(int j=1;j<=pw[i-1];j++){
			cout<<ans[i][j]<<" ";
		}
		cout<<"\n";
	}
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 11828kb

input:

10
441 314 935 337 172 628 445 670 715 953 761 525 432 951 217 785 577 933 855 275 178 664 198 298 4...

output:

404 
602 213 
147 737 965 842 
42 730 351 430 494 493 490 141 
248 974 681 618 505 196 207 805 255 6...

result:

ok 1023 tokens

Test #2:

score: 0
Accepted
time: 2ms
memory: 7744kb

input:

4
10 9 3 11 8 14 15 12 7 13 2 1 4 6 5

output:

12 
11 1 
9 14 13 6 
10 3 8 15 7 2 4 5 

result:

ok 15 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 7776kb

input:

5
15 23 28 30 4 9 27 19 24 3 29 7 22 17 20 26 8 6 13 1 14 5 11 25 2 31 18 16 10 12 21

output:

26 
19 25 
30 7 1 16 
23 9 3 17 6 5 31 12 
15 28 4 27 24 29 22 20 8 13 14 11 2 18 10 21 

result:

ok 31 tokens

Test #4:

score: 0
Accepted
time: 0ms
memory: 9760kb

input:

6
54 6 31 5 26 60 25 46 49 43 33 51 21 28 22 36 7 9 35 39 58 37 59 32 3 48 42 15 18 23 10 12 17 30 5...

output:

12 
36 50 
46 32 8 56 
5 51 39 15 45 16 63 20 
6 60 43 28 9 37 48 23 30 13 61 55 47 38 4 1 
54 31 26...

result:

ok 63 tokens

Test #5:

score: 0
Accepted
time: 2ms
memory: 9664kb

input:

7
116 56 50 18 15 46 36 96 32 77 85 25 76 74 47 10 121 51 86 4 101 79 63 115 75 62 114 28 122 100 17...

output:

35 
45 5 
10 9 30 11 
96 115 21 88 26 83 117 78 
18 25 4 28 105 107 87 123 57 73 81 53 16 48 102 52 ...

result:

ok 127 tokens

Test #6:

score: 0
Accepted
time: 0ms
memory: 11752kb

input:

8
18 138 3 122 199 40 92 144 165 219 196 237 223 60 1 124 65 145 128 107 108 155 62 187 150 29 53 25...

output:

162 
13 42 
216 112 8 130 
124 97 157 12 250 208 185 102 
144 187 230 49 82 136 69 197 141 75 195 18...

result:

ok 255 tokens

Test #7:

score: 0
Accepted
time: 0ms
memory: 11704kb

input:

9
32 353 216 63 482 469 367 60 275 244 109 87 158 505 510 419 71 41 504 128 284 445 264 381 461 59 2...

output:

453 
312 362 
12 10 509 161 
263 288 301 142 365 145 104 192 
419 283 502 97 471 234 316 295 27 25 2...

result:

ok 511 tokens

Test #8:

score: 0
Accepted
time: 1ms
memory: 11824kb

input:

10
373 367 555 336 718 176 655 152 816 779 736 527 107 357 333 936 714 188 185 543 855 759 350 364 6...

output:

568 
1010 1012 
290 132 772 893 
564 894 667 265 264 761 671 15 
190 134 582 282 337 602 181 477 514...

result:

ok 1023 tokens

Test #9:

score: 0
Accepted
time: 0ms
memory: 11756kb

input:

10
400 58 680 758 18 699 340 5 192 936 916 362 142 236 383 801 12 753 622 205 428 486 499 341 979 95...

output:

559 
883 116 
51 320 195 732 
277 687 866 653 128 174 652 317 
76 466 85 171 855 455 542 696 415 523...

result:

ok 1023 tokens