이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |