/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 18ms 1020.0 KiB
#3 Accepted 18ms 928.0 KiB
#4 Accepted 17ms 928.0 KiB
#5 Accepted 17ms 932.0 KiB
#6 Accepted 18ms 928.0 KiB
#7 Accepted 18ms 788.0 KiB
#8 Accepted 17ms 580.0 KiB
#9 Accepted 6ms 536.0 KiB
#10 Accepted 6ms 376.0 KiB
#11 Accepted 17ms 928.0 KiB
#12 Accepted 17ms 836.0 KiB
#13 Accepted 17ms 924.0 KiB
#14 Accepted 17ms 920.0 KiB
#15 Accepted 17ms 924.0 KiB
#16 Accepted 17ms 924.0 KiB
#17 Accepted 17ms 924.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-11-11 03:40:57
Judged By
Score
100
Total Time
18ms
Peak Memory
1020.0 KiB