This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 3e3+5;
int par[maxn];
int cur[maxn];
int tmp[maxn];
int keep[maxn][maxn];
int num[maxn];
int main()
{
//#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
int n; cin >> n;
for(int i = 1; i<= n; i++)
{
int x;
cin >> x;
if(x> 0)
{
if(i>= 3)
{
for(int j = 0; j<= n; j++) tmp[j] = keep[i-2][j];
}
num[i] = x;
tmp[0] = i;
for(int j = 0; j<= n; j++) cur[j] = keep[i][j] = tmp[j];
}
else
{
x *= -1;
int fnd = 0;
for(int j = x-1; j>= 0; j--)
{
if(cur[j])
{
fnd = cur[j]; break;
}
}
//printf("fnd is %d\n", fnd);
memset(tmp, 0, sizeof tmp);
if(fnd>= 2) for(int j = 0; j<= n; j++) tmp[j] = keep[fnd-1][j];
tmp[x] = i;
for(int j = 0; j<= n; j++) cur[j] = keep[i][j] = tmp[j];
}
//printf("i = %d: ", i);
//for(int i = 0; i<= n; i++) printf("%d ", cur[i]);
//printf("\n");
printf("%d\n", num[cur[0]]);
}
}
# | 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... |