답안 #300942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300942 2020-09-17T15:22:57 Z kaplanbar Zalmoxis (BOI18_zalmoxis) C++14
20 / 100
518 ms 262148 KB
#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<stack<int>> v(n + 1);
    int total = k;
    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 {
            v[le.second + 1].push(mn);
            total--;
            q.push((Element){mn + 1, le.first, le.second});
        }
    }
    for(int i = 0; i <= n; i++) {
        stack<int> s;
        // Reverse the stack to process in correct order
        while(v[i].size()) {
            s.push(v[i].top());
            v[i].pop();
        }
        while(s.size()) {
            while(total > 0 && s.top() > 0) {
                total--;
                int x  = s.top();
                s.pop();
                s.push(x - 1);
                s.push(x - 1);
            }
            cout << s.top() << " ";
            s.pop();
        }
        if(i != n) cout << a[i] << " ";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 274 ms 262148 KB Execution killed with signal 9
2 Runtime error 267 ms 262148 KB Execution killed with signal 9
3 Runtime error 274 ms 262144 KB Execution killed with signal 9
4 Runtime error 271 ms 262148 KB Execution killed with signal 9
5 Runtime error 291 ms 262148 KB Execution killed with signal 9
6 Runtime error 260 ms 262148 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 280 ms 262148 KB Execution killed with signal 9
2 Runtime error 295 ms 262148 KB Execution killed with signal 9
3 Runtime error 278 ms 262148 KB Execution killed with signal 9
4 Runtime error 282 ms 262148 KB Execution killed with signal 9
5 Runtime error 269 ms 262144 KB Execution killed with signal 9
6 Runtime error 293 ms 262148 KB Execution killed with signal 9
7 Runtime error 272 ms 262148 KB Execution killed with signal 9
8 Runtime error 267 ms 262148 KB Execution killed with signal 9
9 Runtime error 250 ms 262148 KB Execution killed with signal 9
10 Correct 518 ms 208984 KB Output is correct
11 Runtime error 217 ms 262148 KB Execution killed with signal 9
12 Correct 98 ms 2296 KB Output is correct
13 Correct 131 ms 2296 KB Output is correct
14 Correct 94 ms 2424 KB Output is correct