답안 #750096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750096 2023-05-29T06:45:00 Z vqpahmad Zalmoxis (BOI18_zalmoxis) C++14
45 / 100
483 ms 207064 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;

int n,k;
vector<pii> ans;
int cnt = 0;
void pr(int o){
    if (k>0&&o>0){
        k--;
        pr(o-1);
        pr(o-1);
        return ;
    }
    cnt++;
    cout << o << ' ';
}
int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n >> k;
    stack<int> st;
    st.push(100);
    vector<int> a(n);
    map<int,vector<int>> mp;
    for (int i=0;i<n;i++){
        int x;
        cin >> x;
        a[i] = x;
        if (x < st.top()){
            st.push(x);
            continue;
        }
        if (x > st.top()){
            while (x > st.top()){
                int u = st.top();
                mp[i-1].pb(u);
                while (u==st.top()){
                    st.pop();
                    u++;
                }
                st.push(u);
            }
        }
        if (x==st.top()){
            int u = st.top();
            while (u==st.top()){
                st.pop();
                u++;
            }
            st.push(u);
        }
    }
    int x = 30;
    while (x > st.top()){
        int u = st.top();
        mp[n-1].pb(u);
        while (u==st.top()){
            st.pop();
            u++;
        }
        st.push(u);
    }
    for (int i=0;i<n;i++){
        ans.push_back({a[i],0});
        for (auto it : mp[i]) {
            ans.push_back({it,1});
            k--;
        }
    }
    while (st.size()) st.pop();
    n = sz(ans);
    st.push(ans[0].F);
    for (int i=1;i<n;i++){
        int u = ans[i].F;
        while (st.size()&&u==st.top()){
            st.pop();
            u++;
        }
        st.push(u);
    }
    assert(st.top() == 30 && st.size()==1);
    for (int i=0;i<n;i++){
        if (ans[i].S==0){
            cout << ans[i].F << ' ';
        }
        else pr(ans[i].F);
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 104084 KB Output is correct
2 Correct 402 ms 104152 KB Output is correct
3 Correct 459 ms 104092 KB Output is correct
4 Correct 473 ms 104108 KB Output is correct
5 Correct 438 ms 104124 KB Output is correct
6 Correct 483 ms 104096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 453 ms 206756 KB Execution killed with signal 6
2 Runtime error 381 ms 207064 KB Execution killed with signal 6
3 Runtime error 381 ms 206988 KB Execution killed with signal 6
4 Runtime error 432 ms 206836 KB Execution killed with signal 6
5 Runtime error 392 ms 206752 KB Execution killed with signal 6
6 Runtime error 390 ms 206772 KB Execution killed with signal 6
7 Runtime error 417 ms 206804 KB Execution killed with signal 6
8 Runtime error 449 ms 206804 KB Execution killed with signal 6
9 Runtime error 299 ms 179496 KB Execution killed with signal 6
10 Runtime error 123 ms 73272 KB Execution killed with signal 6
11 Runtime error 199 ms 117764 KB Execution killed with signal 6
12 Correct 74 ms 2280 KB Output is correct
13 Correct 73 ms 2284 KB Output is correct
14 Correct 70 ms 2196 KB Output is correct