Submission #752930

#TimeUsernameProblemLanguageResultExecution timeMemory
752930I_love_Hoang_YenSequence (APIO23_sequence)C++17
0 / 100
2075 ms10060 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()); auto f = [&] (int i) { // +n to make sure result >= 0 if (i < 0) return 0+n; return cnt_less[i] + cnt_equal[i] - cnt_greater[i] + n; }; for (int l = 0; l < n; ++l) { for (int r = l + 1; r < n; ++r) { if (f(r) >= f(l-1)) { int cnt = cnt_equal[r] - (l > 0 ? cnt_equal[l-1] : 0); res = max(res, cnt); } } } } 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...