# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977057 | Tsagana | Sequence (APIO23_sequence) | C++17 | 0 ms | 0 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 "cyberland.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); sort(all(v));
}
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