Submission #977063

#TimeUsernameProblemLanguageResultExecution timeMemory
977063TsaganaSequence (APIO23_sequence)C++17
28 / 100
2075 ms4800 KiB
  #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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...