이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
#include "sequence.h"
using namespace std;
mt19937 rnd(7069);
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;
using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
const int MAX = int(2e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const int N = 500005;
int a[N];
int n, mx;
int sol() {
vi cnt1(n + 1), cnt2(n + 1), pref1(n + 1), pref2(n + 1), v1, v2;
int ret = 0;
bool f = true;
for (int i = 1; i <= n; ++i) {
if (a[i] == mx) {
f = false;
v1.pub(a[i]);
continue;
}
if (f) v1.pub(a[i]);
else v2.pub(a[i]);
}
int sz1 = (int)v1.size();
int sz2 = (int)v2.size();
for (int i = sz1 - 1; i >= 0; --i) {
++cnt1[v1[i]];
if (i == sz1 - 1) pref1[v1[i]] = 1;
else pref1[v1[i]] = pref1[v1[i + 1]] + 1;
}
for (int i = 0; i < sz2; ++i) {
++cnt2[v2[i]];
if (i == 0) pref2[v2[i]] = 1;
else pref2[v2[i]] = pref2[v2[i - 1]] + 1;
}
for (int i = 1; i <= n; ++i) {
ret = max({ ret,cnt1[i],cnt2[i] });
int len = pref1[i] + pref2[i], pref = cnt1[i] + cnt2[i] + n - len;
if (pref >= n / 2 + n % 2) ret = max(ret, cnt1[i] + cnt2[i]);
}
return ret;
}
int sequence(int N, std::vector<int> A) {
n = N;
for (int i = 1; i <= n; ++i) {
a[i] = A[i - 1];
mx = max(mx, a[i]);
}
return sol();
}
/*
7
1 2 3 1 2 1 3
3
9
1 1 2 3 4 3 2 1 1
2
14
2 6 2 5 3 4 2 1 4 3 5 6 3 2
3
*/
# | 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... |