Submission #752937

#TimeUsernameProblemLanguageResultExecution timeMemory
752937I_love_Hoang_YenSequence (APIO23_sequence)C++17
11 / 100
2076 ms10068 KiB
#include "sequence.h" #include <bits/stdc++.h> #define SZ(s) ((int) ((s).size())) using namespace std; int sequence(int n, std::vector<int> a) { int res = 0; int ln = *max_element(a.begin(), a.end()); for (int median = 0; median <= ln; ++median) { vector<int> cnt_less(n, 0); vector<int> cnt_equal(n, 0); vector<int> cnt_greater(n, 0); for (int i = 0; i < n; ++i) { cnt_less[i] = a[i] < median; cnt_equal[i] = a[i] == median; cnt_greater[i] = a[i] > median; } std::partial_sum(cnt_less.begin(), cnt_less.end(), cnt_less.begin()); std::partial_sum(cnt_equal.begin(), cnt_equal.end(), cnt_equal.begin()); std::partial_sum(cnt_greater.begin(), cnt_greater.end(), cnt_greater.begin()); for (int l = 0; l < n; ++l) { for (int r = l + 1; r < n; ++r) { int less = cnt_less[r] - (l == 0 ? 0 : cnt_less[l-1]); int equal = cnt_equal[r] - (l == 0 ? 0 : cnt_equal[l-1]); int greater = cnt_greater[r] - (l == 0 ? 0 : cnt_greater[l-1]); if (less + equal >= greater && less < equal + greater) { res = max(res, equal); } } } } return res; }
#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...