#include <bits/stdc++.h>
#define N 20
using namespace std;
int arr[1<<N];
int brr[1<<N];
map<int,int> mp;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
cin >> n;
for(int i = 0;i<(1<<n);i++){
cin >> arr[i];
brr[i] = arr[i];
}
sort(brr,brr+(1<<n));
int cnt = 0;
int num = 0;
int pw = 1;
for(int i=0;i<(1<<n);i++){
if((i-cnt) == pw){
cnt += pw;
pw = pw*2;
num++;
}
mp[brr[i]] = n-num;
}
for(int i=0;i<(1<<n);i++){
cout << mp[arr[i]] << " ";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
492 KB |
Output is correct |
5 |
Correct |
16 ms |
1260 KB |
Output is correct |
6 |
Correct |
42 ms |
3308 KB |
Output is correct |
7 |
Correct |
87 ms |
5100 KB |
Output is correct |
8 |
Correct |
117 ms |
4716 KB |
Output is correct |
9 |
Correct |
638 ms |
24300 KB |
Output is correct |
10 |
Correct |
1345 ms |
38508 KB |
Output is correct |