| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1286618 | thuhienne | Zalmoxis (BOI18_zalmoxis) | C++20 | 684 ms | 124004 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define re exit(0);
#define thuhien "zalmosis"
int n,k;
vector <int> s;
struct range {
int val;
vector <int> container;
};
vector <range> arr,temp;
multiset <int> a;
multiset <int>::iterator it;
int main() {
ios_base::sync_with_stdio(0);cin.tie(nullptr);
if (fopen(thuhien".inp","r")) {
freopen(thuhien".inp","r",stdin);
freopen(thuhien".out","w",stdout);
}
cin >> n >> k;
arr.resize(n);
for (int i = 0;i < n;i++) {
int a;cin >> a;
arr[i] = {a,{a}};
}
for (int tt = 0;tt < 29;tt++) {
temp.clear();
for (auto x : arr) {
if (temp.size() && temp.back().val == tt && x.val == tt) {
temp.back().val++;
for (auto a : x.container) temp.back().container.push_back(a);
} else temp.push_back(x);
}
arr.clear();
arr = temp;
for (int i = 0;i < arr.size();i++) if (arr[i].val == tt) {
arr[i].val++;
arr[i].container.push_back(tt);
k--;
}
}
//bay gio chi con dung mot so 29
if (k) {
a.insert(29);
while (a.size() != k) {
it = a.end();it--;
a.insert(*it - 1);a.insert(*it - 1);
a.erase(it);
}
}
for (auto x : arr) for (auto y : x.container) cout << y << " ";
if (k) {
it = a.end();it--;
for (;;it--) {
cout << *it << " ";
if (it == a.begin()) break;
}
}
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
