제출 #1158783

#제출 시각아이디문제언어결과실행 시간메모리
1158783fv3Editor (BOI15_edi)C++20
35 / 100
3092 ms7120 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef LOCAL
#include "/home/fv3/prog/debug/debug.h"
#else
#define debug(...) 42
#endif

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    vector<int> state(N+1), par(N+1), value(N+1), level(N+1);
    state[0] = 1;
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        state[i] = 1;
        if (a > 0) {
            value[i] = a;
        } else {
            level[i] = -a;
            for (int j = i-1; j >= 0; j--) {
                if (state[j] && level[j] < level[i]) {
                    state[j] = 0;
                    par[i] = j;
                    while (par[j]) {
                        j = par[j];
                        state[j] ^= 1;
                    }
                    break;
                }
            }
        }
        for (int j = i; j >= 0; j--) {
            if (!level[j] && state[j]) {
                cout << value[j] << "\n";
                break;
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...