#include <bits/stdc++.h>
#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e6 + 7;
int n,k;
int a[N];
int ind = 1,c;
deque <int> q;
vector <pair<int,int> > vec;
main () {
cin >> n >> k;
for (int i = 1; i <= n; i ++)
cin >> a[i];
q.pb(30);
while (ind <= n) {
if (q.front() == a[ind]) {
q.pop_front();
ind ++;
}
else {
if (q.front() > a[ind]) {
int o = q.front();
o --;
q.pop_front();
if (o >= 0) q.push_front(o),q.push_front(o);
}
else {
vec.pb(mk(ind,q.front()));
q.pop_front();
}
}
}
for (int i = 0; i < q.size(); i ++)
vec.pb(mk(ind ++,q[i]));
int cur = k - (int)vec.size();
int last = 1;
for (auto to : vec) {
for (int i = last; i < min(n,to.fr); i ++) {
cout << a[i] << " ";
c ++;
}
q.clear();
q.push_back(to.sc);
deque<int> d;
while (cur > 0 && !q.empty()) {
int o = q.front();
o --;
q.pop_front();
if (o >= 0) q.push_front(o),q.push_front(o),cur --;
else d.pb(o + 1);
}
for (auto to : d) {
cout << to << " ";
c ++;
}
for (auto to : q) {
c ++;
cout << to << " ";
}
last = to.fr;
}
for (int i = last; i <= n; i ++) {
cout << a[i] << " ";
c ++;
}
}
Compilation message
zalmoxis.cpp:24:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:50:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < q.size(); i ++)
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
282 ms |
6264 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
390 ms |
6376 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
392 ms |
6460 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
420 ms |
6484 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
504 ms |
6572 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
386 ms |
6624 KB |
Unexpected end of file - int32 expected |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
390 ms |
6624 KB |
Unexpected end of file - int32 expected |
2 |
Correct |
286 ms |
6648 KB |
Output is correct |
3 |
Correct |
305 ms |
6664 KB |
Output is correct |
4 |
Incorrect |
456 ms |
6664 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
392 ms |
6664 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
355 ms |
6712 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
420 ms |
6712 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
340 ms |
6712 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
327 ms |
7016 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
200 ms |
7016 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
245 ms |
7016 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
101 ms |
7016 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
108 ms |
7016 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
151 ms |
7016 KB |
Unexpected end of file - int32 expected |