Submission #776038

#TimeUsernameProblemLanguageResultExecution timeMemory
776038SharkySequence (APIO23_sequence)C++17
0 / 100
2060 ms12856 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); int median; if (a.empty()) median = b.top(); else if (b.empty()) median = a.top(); else median = (a.top() + b.top()) / 2; cnt[A[j]]++; ans = max(ans, cnt[median]); } } 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...