# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64075 | Just_Solve_The_Problem | Zalmoxis (BOI18_zalmoxis) | C++17 | 371 ms | 6472 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int n, k;
int a[N];
int cnt[N];
main() {
scanf("%d %d", &n, &k);
if (k != 1) return 0;
int mn = inf;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
cnt[a[i]]++;
}
int in;
int cur = -1;
while (1) {
if (cnt[mn] & 1) {
cur = mn;
break;
}
cnt[mn + 1] += cnt[mn] / 2;
cnt[mn] = 0;
mn++;
}
memset(cnt, sizeof cnt, 0);
mn = inf;
for (int i = 1; i <= n; i++) {
if (a[i] < mn) {
mn = a[i];
in = i;
}
}
int l, r;
l = r = in;
cnt[a[l]]++;
mn = inf;
while (1) {
while (l > 1 && a[l - 1] == a[r]) {
l--;
cnt[a[r]]++;
}
while (r < n && a[r + 1] == a[l]) {
r++;
cnt[a[l]]++;
}
while (l > 1 && a[l - 1] == a[r]) {
l--;
cnt[a[r]]++;
}
while (r < n && a[r + 1] == a[l]) {
r++;
cnt[a[l]]++;
}
// cout << l << ' ' << r << endl;
if (cnt[a[l]] & 1) {
in = l;
break;
}
mn = inf;
if (l > 1) mn = min(mn, a[l - 1]);
if (r < n) mn = min(mn, a[r + 1]);
if (mn == inf) {
in = 1;
break;
}
if (mn >= cur) {
in = l;
break;
}
int res = (cnt[a[l]] >> (mn - a[l]));
cnt[mn] += res;
if (l > 1 && a[l - 1] == mn) {
l--;
cnt[a[l]]++;
}
if (r < n && a[r + 1] == mn) {
r++;
cnt[a[r]]++;
}
}
for (int i = 1; i <= n; i++) {
if (i == in) {
printf("%d ", cur);
}
printf("%d ", a[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |