#include "bits/stdc++.h"
#define MAXN 1000009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
stack<int>st;
int arr[MAXN];
void relax(){
while(!st.empty()){
int a=st.top();st.pop();
if(st.empty()){
st.push(a);
break;
}
int b=st.top();
if(a==b){
st.pop();
st.push(a+1);
}
else{
st.push(a);
break;
}
}
}
void solve(int x,int y){
vector<int>v,g;
v.pb(x);
while(y){
if(!v.size()){
swap(v,g);
g.clear();
}
assert(v.back()>=1);
g.pb(v.back()-1);
g.pb(v.back()-1);
v.ppb();y--;
}
tr(it,v)
printf("%d ",*it);
tr(it,g)
printf("%d ",*it);
}
int main(){
//~ freopen("file.in", "r", stdin);
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%d",&arr[i]);
st.push(INF);
vector<PII>ans;
for(int i=1;i<=n;i++){
while(st.top()<arr[i]){
int tmp=st.top();
st.pop();
st.push(tmp+1);
ans.pb(mp(tmp,1));k--;
relax();
}
ans.pb(mp(arr[i],0));
st.push(arr[i]);
relax();
}
while(!st.empty()){
int nd=st.top();st.pop();
if(nd==30)
break;
ans.pb(mp(nd,1));k--;
st.push(nd+1);
relax();
}
assert(k>=0);
tr(it,ans){
if(it->ss==0)
printf("%d ",it->ff);
else{
if((1<<it->ff)<=k){
k-=(1<<it->ff);
for(int j=0;j<(1<<it->ff);j++)
printf("0 ");
}
else
solve(it->ff,k),k=0;
}
}puts("");
assert(!k);
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
~~~~~^~~~~~~~~~~~~~
zalmoxis.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&arr[i]);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
302 ms |
14312 KB |
Output is correct |
2 |
Correct |
298 ms |
14312 KB |
Output is correct |
3 |
Correct |
266 ms |
14392 KB |
Output is correct |
4 |
Correct |
304 ms |
14408 KB |
Output is correct |
5 |
Correct |
311 ms |
14500 KB |
Output is correct |
6 |
Correct |
265 ms |
14500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
14500 KB |
Output is correct |
2 |
Correct |
267 ms |
14500 KB |
Output is correct |
3 |
Incorrect |
376 ms |
14548 KB |
Unexpected end of file - int32 expected |
4 |
Correct |
265 ms |
14548 KB |
Output is correct |
5 |
Correct |
279 ms |
14548 KB |
Output is correct |
6 |
Correct |
261 ms |
14548 KB |
Output is correct |
7 |
Correct |
353 ms |
14548 KB |
Output is correct |
8 |
Correct |
340 ms |
14688 KB |
Output is correct |
9 |
Incorrect |
312 ms |
14688 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
162 ms |
14688 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
237 ms |
14688 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
95 ms |
14688 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
124 ms |
14688 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
104 ms |
14688 KB |
Unexpected end of file - int32 expected |