# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431220 | faresbasbs | Zalmoxis (BOI18_zalmoxis) | C++14 | 501 ms | 16404 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
using lint = long long;
const int MAXN = 1000050;
int n, k, a[MAXN];
int dfs(int x, int c){
if(x == 0 || c == 1){
cout << x << " ";
return 1;
}
else{
int x1 = dfs(x - 1, c / 2);
int x2 = dfs(x - 1, (c + 1) / 2);
return x1 + x2;
}
}
int main(){
cin >> n >> k;
vector<int> v;
for(int i=0; i<n; i++){
cin >> a[i];
v.push_back(a[i]);
}
for(int i=0; i<30; i++){
vector<int> b;
for(int j=0; j<v.size(); ){
if(v[j] > i){
b.push_back(v[j]);
j++;
}
else{
int e = j;
int ans = 0;
while(e < v.size() && v[e] <= i){
ans += (1 << v[e]);
e++;
}
for(int k=j; k<e; k++){
b.push_back(v[k]);
}
if((ans >> i) & 1) b.push_back(i);
j = e;
}
}
v = b;
}
int ptr = 0;
int needy = n + k - (int)v.size();
assert(needy >= 0);
for(int i=0; i<v.size(); i++){
if(ptr < n && v[i] == a[ptr]){
cout << v[i] << " ";
ptr++;
}
else{
needy -= dfs(v[i], needy + 1) - 1;
}
}
cout << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |