Submission #970504

# Submission time Handle Problem Language Result Execution time Memory
970504 2024-04-26T16:05:08 Z anton Sequence (APIO23_sequence) C++17
12 / 100
82 ms 10840 KB
#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

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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 39 ms 10188 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 31 ms 7108 KB Output is correct
3 Correct 82 ms 10532 KB Output is correct
4 Correct 80 ms 10840 KB Output is correct
5 Correct 32 ms 7364 KB Output is correct
6 Correct 44 ms 7364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 10064 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -