이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> vres, vcur, vadd;
void add() {
int tmp = vcur.back();
vadd.push_back(vres.size());
vres.push_back(tmp);
++tmp;
vcur.pop_back();
while (vcur.size() && vcur.back() == tmp) {
vcur.pop_back(), tmp++;
}
vcur.push_back(tmp);
}
void cal(int val, int need) {
if (need == 1) {
cout << val << ' '; return;
}
int tmp = min(need - 1, (1 << (val - 2)));
cal(val - 1, tmp), cal(val - 1, need - tmp);
}
int main() {
ios::sync_with_stdio(false);
int n, m, x;
cin >> n >> m;
cin >> x;
vres.push_back(x), vcur.push_back(x);
for (int i = 1; i < n; ++i) {
int x; cin >> x;
if (vcur.back() > x) {
vres.push_back(x), vcur.push_back(x);
}
else {
while (vcur.back() < x) add();
if (vcur.back() > x) {
vres.push_back(x), vcur.push_back(x);
}
else {
vres.push_back(x);
++x;
vcur.pop_back();
while (vcur.size() && vcur.back() == x) {
vcur.pop_back(), x++;
}
vcur.push_back(x);
}
}
}
while (vcur.back() != 30) add();
int ptr = 0;
for (int i = 0; i < vres.size(); ++i) {
if (ptr < vadd.size() && vadd[ptr] == i) {
++ptr;
int tmp = min(m - ((int)vadd.size() - ptr), 1 << (vres[i] - 1));
m -= tmp;
cal(vres[i], tmp);
}
else cout << vres[i] << ' ';
}
}
컴파일 시 표준 에러 (stderr) 메시지
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:56:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < vres.size(); ++i) {
~~^~~~~~~~~~~~~
zalmoxis.cpp:57:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (ptr < vadd.size() && vadd[ptr] == i) {
~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |