Submission #300819

# Submission time Handle Problem Language Result Execution time Memory
300819 2020-09-17T14:02:14 Z kaplanbar Zalmoxis (BOI18_zalmoxis) C++14
40 / 100
694 ms 18376 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<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;
}

Compilation message

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
1 Correct 640 ms 18376 KB Output is correct
2 Correct 649 ms 18252 KB Output is correct
3 Correct 639 ms 18360 KB Output is correct
4 Correct 653 ms 18300 KB Output is correct
5 Correct 657 ms 18248 KB Output is correct
6 Correct 644 ms 18244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 663 ms 18244 KB Unexpected end of file - int32 expected
2 Incorrect 636 ms 18248 KB Unexpected end of file - int32 expected
3 Incorrect 649 ms 18248 KB Unexpected end of file - int32 expected
4 Incorrect 694 ms 18248 KB Unexpected end of file - int32 expected
5 Incorrect 661 ms 18248 KB Unexpected end of file - int32 expected
6 Correct 670 ms 18376 KB Output is correct
7 Incorrect 648 ms 18376 KB Unexpected end of file - int32 expected
8 Incorrect 677 ms 18248 KB Unexpected end of file - int32 expected
9 Incorrect 555 ms 17864 KB Unexpected end of file - int32 expected
10 Incorrect 199 ms 8792 KB Unexpected end of file - int32 expected
11 Incorrect 329 ms 12632 KB Unexpected end of file - int32 expected
12 Incorrect 1 ms 384 KB Unexpected end of file - int32 expected
13 Incorrect 0 ms 384 KB Unexpected end of file - int32 expected
14 Correct 114 ms 2296 KB Output is correct