# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955089 | Otalp | Sequence (APIO23_sequence) | C++17 | 2096 ms | 13508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
int a[500100];
int s1[500100], s2[500100], c[500100];
int sequence(int n, vector<int> A) {
int ans = 0;
for(int i=1; i<=n; i++){
a[i] = A[i - 1];
}
for(int x=1; x<=n; x++){
vector<pii> q;
int mn=0, mx=0, sum=0;
for(int i=1; i<=n; i++){
if(a[i] == x){
q.pb({mn, mx});
mn = 1e9;
mx = -1e9;
}
if(a[i] > x){
sum += 1;
}
if(a[i] < x){
sum -= 1;
}
mn = min(mn, sum);
mx = max(mx, sum);
}
q.pb({mn, mx});
//cout<<x<<'\n';
for(int i=0; i<q.size(); i++){
//cout<<q[i].ff<<' '<<q[i].ss<<'\n';
for(int j=0; j<i; j++){
int l = q[i].ff - q[j].ss, r = q[i].ss - q[j].ff, L = j - i, R = i - j;
if(r >= L and R >= l){
ans = max(ans, i - j);
}
}
}
}
return ans;
}
Compilation message (stderr)
# | 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... |