| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 867476 | 42kangaroo | Zalmoxis (BOI18_zalmoxis) | C++17 | 123 ms | 24328 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//
// Created by 42kangaroo on 28/10/2023.
//
#include "bits/stdc++.h"
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<pair<int, int>> addBef;
stack<pair<int, int>> st;
auto mergeBack = [&st]() {
while (st.size() > 1) {
auto t = st.top();
st.pop();
if (st.top().second == t.second) {
st.top().second++;
} else {
st.push(t);
break;
}
}
};
for (int i = 0; i < n; ++i) {
while (!st.empty() && st.top().second < a[i]) {
addBef.push_back(st.top());
st.push({-1, st.top().second});
mergeBack();
}
st.push({i, a[i]});
mergeBack();
}
while (!st.empty() && st.top().second < 30) {
addBef.push_back(st.top());
st.push({-1, st.top().second});
mergeBack();
}
vector<int> out;
int addInd = 0;
assert(!addBef.empty());
std::sort(addBef.begin(), addBef.end());
for (int i = 0; i < n; ++i) {
vector<int> hasTo;
while (addInd < addBef.size() && addBef[addInd].first == i) {
hasTo.push_back(addBef[addInd].second);
addInd++;
}
std::reverse(hasTo.begin(), hasTo.end());
for (int q = 0; q < hasTo.size(); ++q) {
int ks = k - addBef.size() + 1;
int p2 = 1;
for (int j = 0; j <= 30; ++j, p2 *= 2) {
if (p2 >= ks || hasTo[q] == j + 1) {
for (int l = 0; l < min(ks, p2); ++l) {
if (l < p2 - ks) out.push_back(hasTo[q] - j + 1);
else out.push_back(hasTo[q] - j);
assert(hasTo[q] - j - 1 >= 0);
}
k -= min(ks, p2) - 1;
break;
}
}
}
out.push_back(a[i]);
}
for (auto e: out) {
cout << e << " ";
}
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
