이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll M = 5e5+10;
ll freq[M];
ll leftfreq[M];
ll rightfreq[M];
int sequence(int N, std::vector<int> A) {
ll ans = 1;
ll xind = -1;
for(int i=0; i<N; i++){
freq[A[i]]++;
}
for(int i=1; i<N; i++){
if(A[i-1]>A[i]){
xind = i-1;
break;
}
}
if(xind==-1){
xind = N-1;
}
if(xind!=0 && xind!=N-1){
map<ll, ll> m;
for(int i=xind; i<N; i++){
m[A[i]] = i;
}
for(int i=0; i<xind; i++){
ll a = A[i];
ll b = m[a];
if(b>0){
ll total = b-i+1;
ll left = i;
ll right = N-1-b;
ll tempfreq = freq[a];
ll big = total-tempfreq;
if(big%2==0){
if(left+right>=big){
ans = max(ans, tempfreq);
}
} else {
if(left+right>=big-1){
ans = max(ans, tempfreq);
}
}
}
}
for(int i=0; i<=xind; i++){
leftfreq[A[i]]++;
ans = max(ans, leftfreq[A[i]]);
}
for(int i=xind+1; i<N; i++){
rightfreq[A[i]]++;
ans = max(ans, rightfreq[A[i]]);
}
return ans;
} else {
for(int i=0; i<N; i++){
leftfreq[A[i]]++;
ans = max(ans, leftfreq[A[i]]);
}
return ans;
}
//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... |