#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();
}
}
}
if (q.size() > 1) assert(0);
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 < 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 ++;
}
cout << c << endl;
}
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:51:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < q.size(); i ++)
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
299 ms |
6272 KB |
Expected EOF |
2 |
Incorrect |
426 ms |
6384 KB |
Expected EOF |
3 |
Incorrect |
305 ms |
6384 KB |
Expected EOF |
4 |
Incorrect |
329 ms |
6580 KB |
Expected EOF |
5 |
Incorrect |
328 ms |
6580 KB |
Expected EOF |
6 |
Incorrect |
347 ms |
6580 KB |
Expected EOF |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
246 ms |
8564 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Incorrect |
343 ms |
10648 KB |
Expected EOF |
3 |
Incorrect |
352 ms |
10648 KB |
Expected EOF |
4 |
Runtime error |
275 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
253 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
262 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
284 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
244 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
201 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
75 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Runtime error |
162 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Runtime error |
4 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Runtime error |
3 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Runtime error |
3 ms |
10648 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |