이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
long long current = 0;
int 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 = 0;
current = 0; //dos
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 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |