#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<pair<int,int>> nums(pow(2,n));
for(int i=0;i<pow(2,n);i++){
int val;
cin >> val;
nums[i] = {val,i};
}
sort(nums.begin(),nums.end());
vector<int> ans(pow(2,n));
for(int i=pow(2,n);i>=0;i--){
if(i!=pow(2,n)-1 and nums[i+1].first==nums[i].first){
int pos = nums[i].second;
ans[pos] = ans[nums[i+1].second];
}
else{
int pos = nums[i].second;
ans[pos] = n - floor(log2(i+1));
}
}
for(auto a:ans) cout << a << " ";
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
860 KB |
Output is correct |
6 |
Correct |
26 ms |
1216 KB |
Output is correct |
7 |
Correct |
49 ms |
2492 KB |
Output is correct |
8 |
Correct |
90 ms |
3876 KB |
Output is correct |
9 |
Correct |
200 ms |
7604 KB |
Output is correct |
10 |
Correct |
415 ms |
14780 KB |
Output is correct |