Submission #982100

#TimeUsernameProblemLanguageResultExecution timeMemory
982100vjudge1Sequence (APIO23_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

int sequence(int n, vector <int> a){


        //unos y tres
        int current = 0, sup = 0, dos = 0;
        for(int i=0; i<n; i++){
            if(a[i] == 1){
                if(current+1>=0) {
                    current++;
                    sup++;
                }
                else {
                current=1;
                sup = 1;
                }
            }
            else current--;
            ans = max(sup, ans);
        }

        sup = current = 0;

        for(int i=0; i<n; i++){
            if(a[i] == 3){
                if(current+1>=0) {
                    current++;
                    sup++;
                }
                else {
                current=1;
                sup = 1;
                }
            }
            else current--;
            ans = max(sup, ans);
        }

        for(int i=0; i<n; i++)
            if(a[i] == 2) dos++;

        return max(dos, ans);

    } 

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:27:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   27 |             ans = max(sup, ans);
      |             ^~~
      |             abs
sequence.cpp:44:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |             ans = max(sup, ans);
      |             ^~~
      |             abs
sequence.cpp:50:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   50 |         return max(dos, ans);
      |                         ^~~
      |                         abs