#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define Maxn 1000003
#define ll long long
#define pb push_back
#define Inf 1000000009
#define ppb() pop_back()
#define pii pair <int , int>
#define mid(x, y) (x + y) / 2
#define all(x) x.begin(),x.end()
#define llInf 1000000000000000009
#define tr(i, c) for(__typeof(c).begin() i = (c).begin() ; i != (c).end() ; i++)
using namespace std;
using namespace __gnu_pbds;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> order;
int n, k;
ll cnt[33];
int A[Maxn];
deque <int> dq;
vector <int> E[Maxn];
int main () {
//freopen ("file.in", "r", stdin);
//freopen ("file.out", "w", stdout);
//srand ((unsigned) time ( NULL ));
//int randomNumber = rand() % 10 + 1;
scanf ("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf ("%d", A + i);
dq.push_front (30);
int p = 0;
int id = 1;
while(id <= n) {
int v = dq.front();
dq.pop_front();
if (v == A[id])
id ++;
else if (v < A[id])
E[id - 1].pb (v), p ++;
else {
v --;
if (v < 0) continue;
dq.push_front (v);
dq.push_front (v);
}
}
for (int i = 0; i < dq.size(); i ++)
E[id - 1].pb (dq[i]);
p += dq.size();
k -= p;
for (int i = 1; i <= n; i++) {
printf ("%d ", A[i]);
if (i == 1)
for (auto j: E[0]) {
memset (cnt, 0, sizeof (cnt));
cnt[j] = 1;
for (int l = j; l >= 1; l--) {
while (k > 0 and cnt[l] > 0)
cnt[l - 1] += 2, cnt[l] --, k --;
for (int h = 1; h <= cnt[l]; h++)
printf ("%d ", l);
}
}
for (auto j: E[i]) {
memset (cnt, 0, sizeof (cnt));
cnt[j] = 1;
for (int l = j; l >= 1; l--) {
while (k > 0 and cnt[l] > 0)
cnt[l - 1] += 2, cnt[l] --, k --;
for (int h = 1; h <= cnt[l]; h++)
printf ("%d ", l);
}
}
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < dq.size(); i ++)
~~^~~~~~~~~~~
zalmoxis.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d%d", &n, &k);
~~~~~~^~~~~~~~~~~~~~~~
zalmoxis.cpp:37:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", A + i);
~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
351 ms |
29820 KB |
Output is correct |
2 |
Correct |
395 ms |
29940 KB |
Output is correct |
3 |
Correct |
303 ms |
29964 KB |
Output is correct |
4 |
Correct |
319 ms |
30084 KB |
Output is correct |
5 |
Correct |
276 ms |
30084 KB |
Output is correct |
6 |
Correct |
419 ms |
30084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
294 ms |
30100 KB |
Output is correct |
2 |
Incorrect |
301 ms |
30100 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
230 ms |
30124 KB |
Unexpected end of file - int32 expected |
4 |
Correct |
289 ms |
30124 KB |
Output is correct |
5 |
Correct |
274 ms |
30124 KB |
Output is correct |
6 |
Correct |
220 ms |
30124 KB |
Output is correct |
7 |
Correct |
283 ms |
30124 KB |
Output is correct |
8 |
Correct |
268 ms |
30176 KB |
Output is correct |
9 |
Incorrect |
279 ms |
32540 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
133 ms |
32540 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
160 ms |
32540 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
29 ms |
32540 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
31 ms |
32540 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
28 ms |
32540 KB |
Unexpected end of file - int32 expected |