이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Code for problem editor by cookiedoth
Generated 24 Oct 2019 at 05.46 P
,##. ,==.
,# #. \ o ',
# # _ _ \ \
# # (_) (_) / ;
`# #' / .'
`##' "=="
-_-
z_z
>_<
*/
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
using namespace std;
template<class T> int chkmax(T &a, T b) {
if (b > a) {
a = b;
return 1;
}
return 0;
}
template<class T> int chkmin(T &a, T b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
while (begin != end) {
out << (*begin) << " ";
begin++;
}
out << endl;
}
template<class T> void output(T x, ostream& out = cerr) {
output(x.begin(), x.end(), out);
}
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int mx = 5010;
int val[mx], ptr[mx], level[mx], active[mx];
void flip(int pos) {
active[pos] ^= 1;
if (level[pos] == 0) {
return;
}
flip(ptr[pos]);
}
signed main() {
fast_io();
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
if (x >= 0) {
// cerr << "add" << endl;
val[i] = x;
active[i] = 1;
}
else {
// cerr << "u" << -x << endl;
level[i] = -x;
active[i] = 1;
ptr[i] = -1;
for (int j = i - 1; i >= 0; --j) {
if (level[j] < level[i] && active[j]) {
flip(j);
ptr[i] = j;
break;
}
}
}
// output(active, active + n);
int res = 0;
for (int j = i; j >= 0; --j) {
if (active[j] && level[j] == 0) {
res = val[j];
break;
}
}
cout << res << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |