Submission #970504

#TimeUsernameProblemLanguageResultExecution timeMemory
970504antonSequence (APIO23_sequence)C++17
12 / 100
82 ms10840 KiB
#include "sequence.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> struct MStack{ vector<pii> st; void push_back(pii val){ if(st.size()==0 || val.first<st.back().first){ st.push_back(val); } } int first_under(int h){ int cur= 0; if(st[0].first<=h){ return -1; } for(int step = (1<<20); step>=1; step/=2){ if(cur+step<st.size()){ if(st[cur+step].first>h){ cur+=step; } } } if(cur == st.size()-1){ return 1e9; } else{ return st[cur+1].second; } } }; int sequence(int N, std::vector<int> A) { vector<int> a; vector<int> oc(3, 0); for(int i = 0; i<N; i++){ oc[A[i]-1] ++; a.push_back(A[i]-1); } for(int i = 0; i<3; i++){ if(2*oc[i]>= N){ return oc[i]; } } int res= max(oc[1], 1); for(int color =0; color<3; color+=2){ int K =0; int S =0; MStack vals; vals.push_back({0, -1}); for(int i = 0; i<N; i++){ K++; if(a[i] == color){ S++; } //cout<<"id "<<vals.first_under(2*S-K)<<" "<<i<<endl; res = max(res, (i-vals.first_under(2*S-K)+1)/2); //cout<<"val "<<i<<" "<<2*S-K<<endl; vals.push_back({2*S-K, i}); } } return res; }

Compilation message (stderr)

sequence.cpp: In member function 'int MStack::first_under(int)':
sequence.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         if(cur+step<st.size()){
      |            ~~~~~~~~^~~~~~~~~~
sequence.cpp:28:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       if(cur == st.size()-1){
      |          ~~~~^~~~~~~~~~~~~~
#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...