답안 #300982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300982 2020-09-17T15:38:56 Z kaplanbar Zalmoxis (BOI18_zalmoxis) C++14
20 / 100
798 ms 262152 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 1e6 + 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;
priority_queue<Element> q;
unordered_map<int, stack<int>> v;
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        q.push((Element){a[i], i, i});
    }
    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});
        }
    }
    int co = 0;
    for(int i = 0; i <= n; i++) {
        co += v[i].size();
    }
    for(int i = 0; i <= n; i++) {
        if(v.find(i) != v.end()) {
            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 745 ms 262148 KB Execution killed with signal 9
2 Runtime error 739 ms 262148 KB Execution killed with signal 9
3 Runtime error 761 ms 262148 KB Execution killed with signal 9
4 Runtime error 736 ms 262148 KB Execution killed with signal 9
5 Runtime error 743 ms 262148 KB Execution killed with signal 9
6 Runtime error 753 ms 262148 KB Execution killed with signal 9
# 결과 실행 시간 메모리 Grader output
1 Runtime error 752 ms 262148 KB Execution killed with signal 9
2 Runtime error 741 ms 262148 KB Execution killed with signal 9
3 Runtime error 751 ms 262148 KB Execution killed with signal 9
4 Runtime error 746 ms 262148 KB Execution killed with signal 9
5 Runtime error 733 ms 262148 KB Execution killed with signal 9
6 Runtime error 750 ms 262152 KB Execution killed with signal 9
7 Runtime error 742 ms 262148 KB Execution killed with signal 9
8 Runtime error 751 ms 262148 KB Execution killed with signal 9
9 Runtime error 798 ms 262148 KB Execution killed with signal 9
10 Correct 651 ms 222812 KB Output is correct
11 Runtime error 626 ms 262148 KB Execution killed with signal 9
12 Correct 94 ms 2300 KB Output is correct
13 Correct 93 ms 2300 KB Output is correct
14 Correct 92 ms 2296 KB Output is correct