이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 2e6 + 5;
struct Element {
int x, l, r;
bool operator<(Element other) const {
if(x == other.x) {
return l > other.l;
}
return x > other.x;
}
};
int n, k, a[N];
priority_queue<Element> q;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for(int i = 0; i < n; i++) {
cin >> a[i];
q.push((Element){a[i], i, i});
}
vector<pair<int,int>> Ans;
while(1) {
if(q.top().x == 30) break;
int mn = q.top().x;
pair<int,int> le = make_pair(q.top().l, q.top().r);
q.pop();
if(mn == q.top().x && le.second == q.top().l - 1) {
auto val = (Element){mn + 1, le.first, q.top().r};
q.pop();
q.push(val);
}
else {
assert(le.second + 1 <= n);
Ans.push_back(make_pair(mn, le.second + 1));
q.push((Element){mn + 1, le.first, le.second});
}
}
stack<pair<int,int>> s;
for(int i = (int)Ans.size() - 1; i >= 0; i--) {
s.push(Ans[i]);
}
int ptr = 0;
int need = k - (int)s.size();
for(int i = 0; i <= n; i++) {
while(s.size()) {
if(s.top().second == i) {
if(need && s.top().first > 0) {
int x = s.top().first;
s.pop();
s.push(make_pair(x - 1, i));
s.push(make_pair(x - 1, i));
need--;
}
else {
cout << s.top().first << " ";
s.pop();
}
}
else {
break;
}
}
if(i != n) cout << a[i] << " ";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:44:9: warning: unused variable 'ptr' [-Wunused-variable]
44 | int ptr = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |