Submission #985192

#TimeUsernameProblemLanguageResultExecution timeMemory
985192CrazyBotBoySequence (APIO23_sequence)C++17
28 / 100
2048 ms49052 KiB
#include "sequence.h" #include <vector> #include <unordered_map> #include <algorithm> #include <iostream> #include <set> using namespace std; void balanceHeaps(multiset<int> &maxHeap, multiset<int> &minHeap) { if (maxHeap.size() > minHeap.size() + 1) { minHeap.insert(*maxHeap.rbegin()); maxHeap.erase(--maxHeap.end()); } else if (minHeap.size() > maxHeap.size()) { maxHeap.insert(*minHeap.begin()); minHeap.erase(minHeap.begin()); } } int sequence(int N, vector<int> A) { int maxOccurrences = 0; for (int l = 0; l < N; ++l) { unordered_map<int, int> freq; multiset<int> minHeap, maxHeap; for (int r = l; r < N; ++r) { int num = A[r]; if (maxHeap.empty() || num <= *maxHeap.rbegin()) { maxHeap.insert(num); } else { minHeap.insert(num); } balanceHeaps(maxHeap, minHeap); freq[num]++; int median1 = *maxHeap.rbegin(); int median2 = (maxHeap.size() + minHeap.size()) % 2 == 0 ? *minHeap.begin() : median1; maxOccurrences = max(maxOccurrences, freq[median1]); if (median1 != median2) { maxOccurrences = max(maxOccurrences, freq[median2]); } } } return maxOccurrences; }
#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...