답안 #345971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
345971 2021-01-08T19:29:14 Z MladenP Zalmoxis (BOI18_zalmoxis) C++17
100 / 100
180 ms 13276 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
using namespace std;
int N, K;
vector<pii> rez;
vector<int> tmp;
void rastavi(int X) {
    tmp.clear();
    tmp.pb(X);
    while(K && !tmp.empty()) {
        int bck = tmp.back(); tmp.pop_back();
        if(bck == 1) {
            cout << bck << ' ';
        } else {
            K--;
            tmp.pb(bck-1);
            tmp.pb(bck-1);
        }
    }
    while(!tmp.empty()) {
        int bck = tmp.back(); tmp.pop_back();
        cout << bck << ' ';
    }
}
void ubaci(int x) {
    while(!tmp.empty() && x == tmp.back()) {
        x++; tmp.pop_back();
    }
    tmp.pb(x);
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N >> K;
    for(int i = 1; i <= N+1; i++) {
        int x;
        if(i <= N) cin >> x;
        else x = 30;
        while(!tmp.empty() && x > tmp.back()) {
            rez.pb({tmp.back(), 1});
            ubaci(tmp.back());
            K--;
        }
        ubaci(x);
        if(i <= N) rez.pb({x, 0});
    }
    for(auto x : rez) {
        if(x.se == 0) {
            cout << x.fi << ' ';
        } else {
            rastavi(x.fi);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 175 ms 12496 KB Output is correct
2 Correct 175 ms 12496 KB Output is correct
3 Correct 173 ms 12496 KB Output is correct
4 Correct 174 ms 12496 KB Output is correct
5 Correct 173 ms 12484 KB Output is correct
6 Correct 173 ms 12368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 12496 KB Output is correct
2 Correct 176 ms 12496 KB Output is correct
3 Correct 175 ms 12624 KB Output is correct
4 Correct 174 ms 12496 KB Output is correct
5 Correct 173 ms 12624 KB Output is correct
6 Correct 179 ms 12496 KB Output is correct
7 Correct 173 ms 12496 KB Output is correct
8 Correct 173 ms 12496 KB Output is correct
9 Correct 162 ms 11600 KB Output is correct
10 Correct 131 ms 13276 KB Output is correct
11 Correct 146 ms 9696 KB Output is correct
12 Correct 113 ms 12508 KB Output is correct
13 Correct 110 ms 12380 KB Output is correct
14 Correct 105 ms 2540 KB Output is correct