# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63397 | rzbt | Zalmoxis (BOI18_zalmoxis) | C++14 | 1098 ms | 62724 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>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1000006
using namespace std;
int n,k;
int l[MAXN],d[MAXN],niz[MAXN];
int orig[MAXN];
vector<int> gde[MAXN];
int main()
{
scanf("%d %d", &n, &k);
for(int i=1;i<=n;i++){
scanf("%d",niz+i);
orig[i]=niz[i];
l[i]=i;
d[i]=i;
}
for(int j=1;j<30;j++){
for(int i=1;i<=n;i++){
if(!niz[i] || niz[i]!=j)continue;
if(niz[i]==niz[d[i]+1]){
niz[d[i]+1]=0;
niz[i]++;
d[i]=d[d[i]+1];
}else{
gde[d[i]].pb(j);
niz[i]++;
k--;
}
i=d[i];
}
}
for(int i=1;i<=n;i++){
printf("%d ",orig[i]);
if(k==0){
for(auto x:gde[i])printf("%d ",x);
continue;
}
reverse(all(gde[i]));
while(!gde[i].empty()){
if(k==0 || gde[i].back()==1){
printf("%d ",gde[i].back());
gde[i].pop_back();
}else{
k--;
int nzm=gde[i].back()-1;
gde[i].pop_back();
gde[i].pb(nzm);gde[i].pb(nzm);
}
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |