/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 15ms 924.0 KiB
#3 Accepted 15ms 924.0 KiB
#4 Accepted 15ms 928.0 KiB
#5 Accepted 15ms 924.0 KiB
#6 Accepted 15ms 796.0 KiB
#7 Accepted 15ms 916.0 KiB
#8 Accepted 15ms 540.0 KiB
#9 Accepted 5ms 328.0 KiB
#10 Accepted 5ms 512.0 KiB
#11 Accepted 15ms 924.0 KiB
#12 Accepted 15ms 916.0 KiB
#13 Accepted 15ms 924.0 KiB
#14 Accepted 15ms 928.0 KiB
#15 Accepted 15ms 920.0 KiB
#16 Accepted 14ms 924.0 KiB
#17 Accepted 15ms 916.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n];
        for(int i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        int one = 0;
        int thr = 0;
        int len= 0;
        for(int i=1; i<n+1; i++)
        {
            if(arr[i-1]==1)
            {   
            if(one>0)
            {
                one = min(one,i);
            }
            else
            {
                one = i;
            }
            }

            else if(arr[i-1]==2)
            {
                one = 0;
                continue;
            }
            else if(arr[i-1]==3)
            {
                if(one>0)
                {
                    len = max(len,(i-one+1));
                }
                
            }

        }
        cout<<len<<endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1036 Perfect subarray
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-12 11:55:41
Judged At
2024-03-12 11:55:41
Judged By
Score
100
Total Time
15ms
Peak Memory
928.0 KiB