Submission #871777

#TimeUsernameProblemLanguageResultExecution timeMemory
871777vjudge1Sequence (APIO23_sequence)C++17
0 / 100
2039 ms4764 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; using ll = long long; int sequence(int n, std::vector<int> a) { ll mx = 0; for (int i = 0; i < n; ++i) { map < int, ll > m; int mid = -1, mi = 0; for (int j = i; j >= 0; --j) { ++m[a[j]]; if (mid == -1) mid = a[j]; if (a[j] < mid) ++mi; if ((i - j + 1) / 2 < mi) mid = prev (m.find (mid))->first, mi -= m[mid]; if (mi + m[mid] <= (i - j + 1) / 2) mi += m[mid], mid = next (m.find (mid))->first; ll ans = m[mid]; if (mi + m[mid] <= (i - j + 2) / 2) ans = max (ans, next (m.find (mid))->second); mx = max (mx, ans); } } return mx; }
#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...