Submission #1061144

#TimeUsernameProblemLanguageResultExecution timeMemory
1061144KerimSequence (APIO23_sequence)C++17
12 / 100
51 ms16460 KiB
#include "sequence.h" #include <vector> #include "bits/stdc++.h" using namespace std; int sequence(int N, std::vector<int> arr) { int cnt = 0; vector<int> one{0}, two{0}; vector<int> A(N+1), B(N+1); for (int i = 0; i < N; i++){ int x = arr[i]; assert(1 <= x and x <= 3); A[i+1] = A[i]-1; B[i+1] = B[i]-1; if (x == 1) A[i+1] += 2, one.push_back(i+1); else if (x == 3) B[i+1] += 2, two.push_back(i+1); else cnt += 1; } int st = 1, en = N; while (st < en){ int mid = (st+en+1) >> 1; bool ok = 0; for (int i = mid; i < one.size(); i++) ok |= (A[one[i]] >= A[one[i-mid]]); for (int i = mid; i < two.size(); i++) ok |= (B[two[i]] >= B[two[i-mid]]); if (ok) st = mid; else en = mid-1; } return max(cnt, st); }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:26:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = mid; i < one.size(); i++)
      |                           ~~^~~~~~~~~~~~
sequence.cpp:28:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (int i = mid; i < two.size(); i++)
      |                           ~~^~~~~~~~~~~~
#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...