1143A - The Doors - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n=int(input())
x=list(map(int, input().split()))
x.reverse()
p=x.index(0)
q=x.index(1)
if p>q:
    r=n-p
else:
    r=n-q
print(r)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l=0,r=0,j,ra,la;
    cin>>n;
    int a[n];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0)
            l++;
        else
            r++;
    }
    ra=r;
    la=l;
    for(j=1;j<=n;j++){
        if(a[j]==0)
            la--;
        else
            ra--;
        if(la==0||ra==0)
            break;
    }
    cout<<j;
    return 0;

}


Comments

Submit
0 Comments
More Questions

22B - Bargaining Table
1490B - Balanced Remainders
264A - Escape from Stones
1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine