Submission #982290

#TimeUsernameProblemLanguageResultExecution timeMemory
982290vjudge1Sequence (APIO23_sequence)C++17
12 / 100
78 ms11288 KiB
#include "sequence.h" #include<bits/stdc++.h> using namespace std; priority_queue<int>pql; priority_queue<int,vector<int>,greater<>>pqu; map<int,int>st2; int sequence(int N, std::vector<int> A) { vector<int>V=A,ones,threes; int ans=0,prev,cnt; sort(V.begin(),V.end()); int med=2; if(V[N/2]-2) med=V[N/2]; else med=V[N-1>>1]; if(med-2) return count(V.begin(),V.end(),med); ans=count(V.begin(),V.end(),med); if(ans*2>=N) return ans; for(int i=0;i<N;i++) if(A[i]<2) ones.push_back(i); else if(A[i]-2) threes.push_back(i); map<int,int>mp; mp[0]=0; prev=ones[0],cnt=1; for(int i=1;i<ones.size();i++){ cnt+=2-ones[i]+prev; if(mp.begin()->first>cnt) mp[cnt]=i; else ans=max(ans,1+i-(--mp.upper_bound(cnt))->second); prev=ones[i]; } mp.clear(); mp[0]=0; prev=threes[0],cnt=1; for(int i=1;i<size(threes);i++){ cnt+=2-threes[i]+prev; if(mp.begin()->first>cnt) mp[cnt]=i; else ans=max(ans,1+i-(--mp.upper_bound(cnt))->second); prev=threes[i]; } mp.clear(); return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:13:17: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   13 |     else med=V[N-1>>1];
      |                ~^~
sequence.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=1;i<ones.size();i++){
      |                 ~^~~~~~~~~~~~
sequence.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int i=1;i<size(threes);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...