# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
442460 | JovanB | Zalmoxis (BOI18_zalmoxis) | C++17 | 265 ms | 61212 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 ll = long long;
using ld = long double;
using T = pair <int, pair <int, int>>;
const int MAXN = 1000000;
vector <int> dod[MAXN+5];
vector <T> vec;
vector <T> nvec;
int a[MAXN+5];
void pisi(int x, int times){
if(times == 1){
cout << x << " ";
return;
}
if((1<<(x-1)) >= times-1){
pisi(x-1, times-1);
cout << x-1 << " ";
return;
}
else{
pisi(x-1, (1<<(x-1)));
times -= (1<<(x-1));
pisi(x-1, times);
}
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> a[i];
vec.push_back({a[i], {i, i}});
}
for(int j=0; j<=29; j++){
nvec.clear();
//for(auto c : vec) cout << c.first << " " << c.second.first << " " << c.second.second << endl;
for(int i=0; i<vec.size(); i++){
if(vec[i].first == j){
if(i == vec.size()-1 || vec[i+1].first != j){
dod[vec[i].second.second].push_back(j);
nvec.push_back({j+1, vec[i].second});
}
else{
nvec.push_back({j+1, {vec[i].second.first, vec[i+1].second.second}});
i++;
}
}
else nvec.push_back(vec[i]);
}
//cout << endl;
vec.clear();
for(auto c : nvec) vec.push_back(c);
}
for(int i=1; i<=n; i++){
m -= dod[i].size();
}
for(int i=1; i<=n; i++){
cout << a[i] << " ";
for(auto c : dod[i]){
if((1<<c)-1 <= m){
m -= (1<<c)-1;
pisi(c, (1<<c));
}
else{
pisi(c, m+1);
m = 0;
}
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |