답안 #982290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982290 2024-05-14T05:59:02 Z vjudge1 서열 (APIO23_sequence) C++17
12 / 100
78 ms 11288 KB
#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

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++){
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 42 ms 6244 KB Output is correct
3 Correct 78 ms 11288 KB Output is correct
4 Correct 75 ms 11200 KB Output is correct
5 Correct 43 ms 7248 KB Output is correct
6 Correct 45 ms 9368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 6224 KB Output is correct
2 Correct 75 ms 6300 KB Output is correct
3 Incorrect 71 ms 6224 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -