제출 #1043892

#제출 시각아이디문제언어결과실행 시간메모리
104389212345678Editor (BOI15_edi)C++17
20 / 100
28 ms604 KiB
#include <bits/stdc++.h> using namespace std; const int nx=5e3+5; int n, a, t[nx], vl[nx], p[nx], vs[nx]; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) { cin>>t[i]; vs[i]=1; if (t[i]>0) vl[i]=t[i], t[i]=0, p[i]=i; else { t[i]=-t[i]; for (int j=1; j<i; j++) if (vs[j]&&t[j]<t[i]) p[i]=j; } int cnt=0, cur=i; while (p[cur]!=cur) { if (cnt) vs[cur]=!vs[cur]; cnt++; cur=p[cur]; } if (cnt) vs[cur]=!vs[cur]; int res=0; for (int j=1; j<=i; j++) if (!t[j]&&vs[j]) res=vl[j]; cout<<res<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...