#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
ll const inf = 1e9;
ll const mod = 998244853;
ld const eps = 1e-9;
bool f(pii A, pii B){
if(A.st < B.st) return true;
else if(A.st > B.st) return false;
else A.nd > B.nd;
}
int k;
void expand(int num){
if(num == 0){
cout << 0 <<' ';
return;
}
if(k == 0){
cout << num <<' ';
return;
}
--k;
expand(num - 1);
expand(num - 1);
}
int main()
{
int n;
cin >> n >> k;
int a[n];
int b[n];
int MIN = 40;
int nxt[n];
fr(i, 0, n){
cin >> a[i];
b[i] = a[i];
MIN = min(a[i], MIN);
nxt[i] = i + 1;
}
nxt[n - 1] = n;
vector<pii> v;
int sz = n;
fr(mi, MIN, 30){
int p = 0;
int CNT = 0;
while(1){
if(p == n){
break;
}
if(nxt[p] == n){
if(a[p] == mi){
v.pb({p, mi});
a[p] ++;
}
}
else if(a[p] == mi){
if(a[nxt[p]] == mi){
a[p] = mi + 1;
nxt[p] = nxt[nxt[p]];
CNT ++;
}
else{
v.pb({p, mi});
a[p] = mi + 1;
}
}
p = nxt[p];
}
sz -= CNT;
p = 0;
}
sort(v.begin(), v.end(), f);
int j = 0;
k -= (int)v.size();
if(k < 0) cout << 2 / 0 << endl;
fr(i, 0, n){
while(j < v.size() && v[j].st == i){
expand(v[j].nd);
j ++;
}
cout << b[i] <<' ';
}
if(k == 0) cout << 2 / 0 << endl;
cout <<endl;
return 0;
}
Compilation message
zalmoxis.cpp: In function 'bool f(pii, pii)':
zalmoxis.cpp:21:20: warning: statement has no effect [-Wunused-value]
else A.nd > B.nd;
^
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:91:29: warning: division by zero [-Wdiv-by-zero]
if(k < 0) cout << 2 / 0 << endl;
~~^~~
zalmoxis.cpp:93:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(j < v.size() && v[j].st == i){
~~^~~~~~~~~~
zalmoxis.cpp:99:30: warning: division by zero [-Wdiv-by-zero]
if(k == 0) cout << 2 / 0 << endl;
~~^~~
zalmoxis.cpp: In function 'bool f(pii, pii)':
zalmoxis.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
416 ms |
26264 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Runtime error |
412 ms |
26332 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
3 |
Runtime error |
410 ms |
26304 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
4 |
Runtime error |
411 ms |
26356 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
5 |
Runtime error |
413 ms |
26316 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
6 |
Runtime error |
410 ms |
26192 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
435 ms |
26300 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
2 |
Runtime error |
408 ms |
26344 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
3 |
Runtime error |
411 ms |
26368 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
4 |
Runtime error |
417 ms |
26324 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
5 |
Runtime error |
413 ms |
26360 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
6 |
Runtime error |
412 ms |
26320 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
7 |
Runtime error |
432 ms |
26372 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
8 |
Runtime error |
413 ms |
26236 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
9 |
Runtime error |
383 ms |
23992 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
10 |
Runtime error |
219 ms |
12132 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
11 |
Runtime error |
287 ms |
17132 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
12 |
Runtime error |
107 ms |
2464 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
13 |
Runtime error |
102 ms |
2448 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |
14 |
Runtime error |
101 ms |
2424 KB |
Execution killed with signal 8 (could be triggered by violating memory limits) |