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"
//OP
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pi pair<int, int >
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define mset multiset
#define F first
#define S second
using namespace std;
struct arr {
vector<int> v;
void res() {v.clear();}
void insert(int x) {
v.pb(x);
for (int i = v.size()-1; i > 0 && v[i] < v[i-1]; i--) swap(v[i], v[i-1]);
}
pair<int, int> med() {
int n = v.size();
if (n % 2 == 1) {
return {v[n/2], -1};
}
else {
return {v[n/2-1], v[n/2]};
}
}
int calc() {
pair<int, int> p = med();
int c1 = 0, c2 = 0;
for (auto i: v) {
if (i == p.F) c1++;
if (i == p.S) c2++;
}
return max(c1, c2);
}
};
int sequence(int N, std::vector<int> A) {
int ans = 0;
for (int i = 0; i < N; i++) {
arr a; a.res();
for (int j = i; j < N; j++) {
a.insert(A[j]);
ans = max(ans, a.calc());
// for (auto k: a.v) cout << k << ' ';
// cout << " - " << ans << '\n';
}
}
return ans;
}
//ED
# | 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... |