제출 #957595

#제출 시각아이디문제언어결과실행 시간메모리
957595zeta7532서열 (APIO23_sequence)C++17
28 / 100
1285 ms2097152 KiB
#include "sequence.h" #include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = int; const ll mod = 998244353; #define fi first #define se second #define rep(i,n) for(ll i=0;i<n;i++) #define all(x) x.begin(),x.end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr) int sequence(int N, std::vector<int> A) { int ans=0; vector<vector<int>> cum(N+1,vector<ll>(N+1,0)); rep(i,N) cum[i+1][A[i]]++; rep(i,N) rep(j,N+1) cum[i+1][j]+=cum[i][j]; rep(l,N){ multiset<ll> s1,s2; for(ll r=l;r<N;r++){ s2.insert(A[r]); while(s1.size()>0&&s2.size()>0&&(*s1.rbegin()>*s2.begin())){ s1.insert(*s2.begin()); s2.erase(s2.find(*s2.begin())); } while(((ll)s2.size()-(ll)s1.size())>=2){ s1.insert(*s2.begin()); s2.erase(s2.find(*s2.begin())); } while(((ll)s1.size()-(ll)s2.size())>=2){ s2.insert(*s1.rbegin()); s1.erase(s1.find(*s1.rbegin())); } if(s1.size()>=s2.size()) ans=max(ans,cum[r+1][*s1.rbegin()]-cum[l][*s1.rbegin()]); if(s2.size()>=s1.size()) ans=max(ans,cum[r+1][*s2.begin()]-cum[l][*s2.begin()]); } } return ans; }
#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...