#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;}
int arr[MAXN];
vector<int>adj[MAXN];
vector<int>vec;
void solve(int x,int y){
vector<int>v,g;
v.pb(x);
while(y){
if(!v.size()){
swap(v,g);
g.clear();
}
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);
stack<PII>st;
st.push(mp(arr[1],1));
int cnt=0;
for(int i=2;i<=n;i++){
int now=arr[i],ok=0;
while(!ok){
while(!st.empty() and st.top().ff==now){
st.pop();
now++;
}
if(st.empty())
st.push(mp(now,i)),ok=1;
else{
if(st.top().ff<now){
while(st.top().ff<now){
PII tmp=st.top();st.pop();
if(st.empty() or st.top().ff!=tmp.ff)
adj[tmp.ss].pb(tmp.ff),cnt++;
else
st.pop();
st.push(mp(tmp.ff+1,tmp.ss));
}
}
else
st.push(mp(now,i)),ok=1;
}
}
}
while(!st.empty()){
PII tmp=st.top();st.pop();
if(tmp.ff==30)
break;
if(!st.empty() and st.top().ff==tmp.ff)
st.pop();
else
adj[tmp.ss].pb(tmp.ff),cnt++;
st.push(mp(tmp.ff+1,tmp.ss));
}
assert(cnt<=k);
k-=cnt;
for(int i=1;i<=n;i++){
printf("%d ",arr[i]);
tr(it,adj[i]){
if((1<<*it)<=k){
k-=(1<<*it);
for(int j=0;j<(1<<(*it));j++)
printf("0 ");
}
else
solve(*it,k),k=0;
}
}puts("");
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:44: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:46: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 |
310 ms |
30004 KB |
Output is correct |
2 |
Correct |
301 ms |
30012 KB |
Output is correct |
3 |
Correct |
278 ms |
30012 KB |
Output is correct |
4 |
Correct |
329 ms |
30012 KB |
Output is correct |
5 |
Correct |
335 ms |
30088 KB |
Output is correct |
6 |
Correct |
255 ms |
30088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
283 ms |
30088 KB |
not a zalsequence |
2 |
Runtime error |
216 ms |
55896 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Runtime error |
236 ms |
56056 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Incorrect |
293 ms |
57888 KB |
not a zalsequence |
5 |
Incorrect |
277 ms |
57888 KB |
not a zalsequence |
6 |
Correct |
238 ms |
57888 KB |
Output is correct |
7 |
Incorrect |
285 ms |
57888 KB |
not a zalsequence |
8 |
Incorrect |
267 ms |
57892 KB |
not a zalsequence |
9 |
Runtime error |
203 ms |
65640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Incorrect |
188 ms |
65640 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
266 ms |
66384 KB |
not a zalsequence |
12 |
Incorrect |
101 ms |
66384 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
105 ms |
66384 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
116 ms |
66384 KB |
Unexpected end of file - int32 expected |