이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 5e5 + 5;
vector<int> pos[maxn];
int sequence(int N, vector<int> A) {
for(int i = 0;i < N;i++) pos[A[i]].pb(i);
int X = 0;
for(int i = 1;i < N;i++)
if(A[i] > A[X]) X = i;
int l = 0, ans = 0;
for(int i = 1;i <= N;i++) {
if(pos[i].size() == 0) continue;
int lo = pos[i][0], hi = pos[i].back();
if(hi < X || lo > X) ans = max(ans, (int)pos[i].size());
else {
int e = (int)pos[i].size();
int g = N - e - l;
if(l < g - e) {
int x = 0, y = 0;
for(int j : pos[i])
if(j < X) x++;
else y++;
ans = max(ans, max(x, y));
} else ans = max(ans, e);
}
l += (int)pos[i].size();
}
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... |