제출 #849680

#제출 시각아이디문제언어결과실행 시간메모리
849680adhityamv서열 (APIO23_sequence)C++17
0 / 100
2054 ms56924 KiB
#include <bits/stdc++.h> using namespace std; int sequence(int n,vector<int> A){ int x=0; int a[n]; int b[n]; int cnt[n]={}; vector<int> ind[n]; for(int i=0;i<n;i++){ A[i]--; cnt[A[i]]++; if(A[i]>0) a[i]=-1; else a[i]=1; if(A[i]<0) b[i]=-1; else b[i]=1; ind[A[i]].push_back(i); } int ans=0; while(x<n){ if(cnt[x]!=0){ int spa[2*n+1]; int epa[2*n+1]; for(int i=0;i<=2*n;i++){ spa[i]=-1; epa[i]=-1; } int spb[2*n+1]; int epb[2*n+1]; for(int i=0;i<=2*n;i++){ spb[i]=-1; epb[i]=-1; } int prefixa[n+1]; int prefixb[n+1]; int cva=0; int cvb=0; for(int i=0;i<=n;i++){ if(spa[cva+n]==-1) spa[cva+n]=i; if(spb[cvb+n]==-1) spb[cvb+n]=i; epa[cva+n]=i; epb[cvb+n]=i; prefixa[i]=cva; prefixb[i]=cvb; if(i<n){ cva+=a[i]; cvb+=b[i]; } } for(int i=0;i<=2*n;i++){ if(spa[i]!=-1){ ans=max(ans,prefixb[epa[i]]-prefixb[spa[i]]); } if(spb[i]!=-1){ ans=max(ans,prefixa[epb[i]]-prefixa[spb[i]]); } if(0<i && i<=n)if(prefixa[i]<=prefixa[n] && prefixb[i]<=prefixb[n]){ ans=max(ans,prefixb[n]+prefixa[n]-prefixb[i]-prefixa[i]); } } } if(x+1<n){ for(int i:ind[x]){ b[i]=-1; } for(int i:ind[x+1]){ a[i]=1; } } x++; } return ans/2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...