Submission #776046

#TimeUsernameProblemLanguageResultExecution timeMemory
776046SharkySequence (APIO23_sequence)C++17
28 / 100
2078 ms9548 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; #define DEBUG if (1) int sequence(int N, std::vector<int> A) { int ans = 0; for (int i = 0; i < N; i++) { priority_queue<int> a; priority_queue<int, vector<int>, greater<int>> b; vector<int> cnt(N + 1, 0); for (int j = i; j < N; j++) { if (a.empty() && b.empty()) a.push(A[j]); else if (a.empty() || (a.size() <= b.size())) { if (A[j] <= b.top()) a.push(A[j]); else { a.push(b.top()); b.pop(); b.push(A[j]); } } else if (b.empty() || (a.size() > b.size())) { if (A[j] >= a.top()) b.push(A[j]); else { b.push(a.top()); a.pop(); a.push(A[j]); } } else assert(false); vector<int> median; if (a.size() > b.size()) median = {a.top()}; else if (b.size() > a.size()) median = {b.top()}; else median = {a.top(), b.top()}; cnt[A[j]]++; for (int& med : median) ans = max(ans, cnt[med]); } } return ans; }
#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...