제출 #982096

#제출 시각아이디문제언어결과실행 시간메모리
982096vjudge1서열 (APIO23_sequence)C++17
28 / 100
2147 ms2097152 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset; int sequence(int n, vector <int> a){ bool sp = 1; for(int i=0; i<n; i++){ if(a[i]>3) sp = 0; } int ans = 0; if(sp){ //unos y tres int current = 0, sup = 0, dos = 0; for(int i=0; i<n; i++){ if(a[i] == 1){ if(current+1>=0) { current++; sup++; } else { current=1; sup = 1; } } else current--; ans = max(sup, ans); } sup = current = 0; for(int i=0; i<n; i++){ if(a[i] == 3){ if(current+1>=0) { current++; sup++; } else { current=1; sup = 1; } } else current--; ans = max(sup, ans); } for(int i=0; i<n; i++) if(a[i] == 2) dos++; return max(dos, ans); } vector <vector <int>> repe(n+1, vector<int>(n+1)); for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ repe[i][j] = repe[i][j-1] + (a[j-1] == i); } } for(int i=0; i<n; i++){ ordered_mset st; for(int j=i; j<n; j++){ st.insert(a[j]); auto x = st.find_by_order((j-i)/2); auto y = st.find_by_order((j-i+1)/2); //cout<<i<<' '<<j<<' '<<*x<<' '<<*y<<endl; ans = max(ans, repe[*x][j+1]-repe[*x][i]); ans = max(ans, repe[*y][j+1]-repe[*y][i]); } st.clear(); } 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...