#include <bits/stdc++.h>
using namespace std;
int n,k,v[1000010];
queue<int>ad[1000010];
vector<pair<int,int>>val[35];
void scrie(int val)
{
if(val==0||k==0)
{
cout<<val<<' ';
return;
}
--k;
scrie(val-1);
scrie(val-1);
return;
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>v[i];
val[v[i]].push_back({i,i});
}
for(int va=0;va<=29;++va)
{
sort(val[va].begin(),val[va].end());
int sz=val[va].size();
for(int i=0;i<sz;++i)
{
if(i+1==sz||val[va][i].second+1!=val[va][i+1].first)
{
--k;
ad[val[va][i].second].push(va);
val[va+1].push_back(val[va][i]);
}
else
{
val[va+1].push_back({val[va][i].first,val[va][i+1].second});
++i;
}
}
val[va].clear();
}
if(k<0)
return -1;
if(val[30].size()!=1)
return -1;
if(val[30][0].first!=1||val[30][0].second!=n)
return -1;
for(int i=1;i<=n;++i)
{
cout<<v[i]<<' ';
while(!ad[i].empty())
{
scrie(ad[i].front());
ad[i].pop();
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
106 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Runtime error |
106 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Runtime error |
98 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Runtime error |
99 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Runtime error |
98 ms |
262144 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
110 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Runtime error |
99 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Runtime error |
100 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Runtime error |
109 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Runtime error |
111 ms |
262144 KB |
Execution killed with signal 9 |
6 |
Runtime error |
113 ms |
262144 KB |
Execution killed with signal 9 |
7 |
Runtime error |
124 ms |
262144 KB |
Execution killed with signal 9 |
8 |
Runtime error |
105 ms |
262144 KB |
Execution killed with signal 9 |
9 |
Runtime error |
101 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Runtime error |
108 ms |
262144 KB |
Execution killed with signal 9 |
11 |
Runtime error |
105 ms |
262144 KB |
Execution killed with signal 9 |
12 |
Runtime error |
104 ms |
262144 KB |
Execution killed with signal 9 |
13 |
Runtime error |
101 ms |
262144 KB |
Execution killed with signal 9 |
14 |
Runtime error |
102 ms |
262144 KB |
Execution killed with signal 9 |