Submission #981349

#TimeUsernameProblemLanguageResultExecution timeMemory
981349math_rabbit_1028Sequence (APIO23_sequence)C++17
11 / 100
2052 ms35944 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; int n, m, ans = 0; vector<int> arr, vec; vector<int> pos[505050]; int sequence(int N, vector<int> A) { n = N; arr = A; sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end()); m = A.size(); for (int i = 0; i < n; i++) { arr[i] = lower_bound(A.begin(), A.end(), arr[i]) - A.begin(); } for (int i = 0; i < n; i++) { pos[arr[i]].push_back(i); } for (int t = 0; t < m; t++) { vec.clear(); for (int i = 0; i < n; i++) { if (t == arr[i]) vec.push_back(0); if (t > arr[i]) vec.push_back(1); if (t < arr[i]) vec.push_back(-1); } for (int s = 0; s < n; s++) { int a = 0, b = 0, c = 0; for (int e = s; e < n; e++) { int k = (e-s+1)/2; if (vec[e] == -1) a++; if (vec[e] == 0) b++; if (a <= k && k <= a+b-(e-s+1)%2) ans = max(ans, b); /* -1 : a 0 : b 1 : c 합 짝수(2k ) => a <= n/2 <= a+b 합 홀수(2k+1) => a <= n/2 <= a+b-1 */ } } } return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:33:31: warning: unused variable 'c' [-Wunused-variable]
   33 |             int a = 0, b = 0, c = 0;
      |                               ^
#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...