#include <bits/stdc++.h>
#define DIM 1000010
using namespace std;
int v[DIM];
vector <int> L[DIM];
pair <int,int> sol[DIM];
int n,i,j,poz,k,sol_poz,idx,el;
int solve (int val){
if (v[idx] == val){ /// am deja valoarea pe care o caut
idx++;
return idx;
}
if (!val)
return 0;
/// stanga
int poz = solve (val-1);
if (poz > n || v[poz] > val-1){
/// sunt obligata sa pun aici val
L[poz-1].push_back(val-1);
k--;
/*sol = val-1;
sol_poz = poz-1;*/
return poz;
}
/// dreapta
return solve (val-1);
}
int main (){
// ifstream cin ("zalmoxis.in");
// ofstream cout ("zalmoxis.out");
cin>>n>>k;
for (i=1;i<=n;i++)
cin>>v[i];
idx = 1;
solve (30);
for (i=1;i<=n;i++){
sol[++el] = make_pair(v[i],0);
//cout<<v[i]<<" ";
for (int j=0;j<L[i].size();j++)
sol[++el] = make_pair(L[i][j],1);
}
for (i=1;i<=el;i++){
if (!k){
cout<<sol[i].first<<" ";
continue;
}
if (!sol[i].second)
cout<<sol[i].first<<" ";
else {
/// inseamna ca pot sa il mai descompun
int x = sol[i].first;
if (x < k){
k -= x;
cout<<1<<" ";
for (j=1;j<=x-1;j++)
cout<<j<<" ";
} else {
cout<<x-k<<" ";
for (j=x-k;j<x;j++)
cout<<j<<" ";
}
}
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<L[i].size();j++)
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
339 ms |
37624 KB |
Output is correct |
2 |
Correct |
334 ms |
37496 KB |
Output is correct |
3 |
Correct |
330 ms |
37624 KB |
Output is correct |
4 |
Correct |
339 ms |
37628 KB |
Output is correct |
5 |
Correct |
336 ms |
37624 KB |
Output is correct |
6 |
Correct |
329 ms |
37624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
349 ms |
37624 KB |
Unexpected end of file - int32 expected |
2 |
Correct |
337 ms |
37624 KB |
Output is correct |
3 |
Incorrect |
336 ms |
37752 KB |
Expected EOF |
4 |
Incorrect |
341 ms |
37624 KB |
Expected EOF |
5 |
Incorrect |
325 ms |
37624 KB |
Expected EOF |
6 |
Incorrect |
328 ms |
37624 KB |
Expected EOF |
7 |
Incorrect |
340 ms |
37624 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
348 ms |
37624 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
302 ms |
39928 KB |
Expected EOF |
10 |
Incorrect |
179 ms |
32888 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
231 ms |
36472 KB |
Expected EOF |
12 |
Incorrect |
19 ms |
23800 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
18 ms |
23800 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
19 ms |
23800 KB |
Unexpected end of file - int32 expected |