Created
March 24, 2020 06:31
-
-
Save officialcjunior/da93d5e7dfc5f84490e8d41f95897161 to your computer and use it in GitHub Desktop.
Solution to 1244B of the codeforces problemset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int t, n, max, i; | |
scanf("%d",&t); // test cases | |
while(t--) | |
{ | |
scanf("%d",&n); // n=number of rooms | |
char s[n+1]; | |
max=0; | |
scanf("%s",s); //arrays | |
for(i=0;s[i]!='\0';i++) | |
if(s[i]=='1') //if there's a staircase | |
{ | |
if(i+1>max) max=i+1; //from which side, the steps are max | |
if(n-i>max) max=n-i; | |
} | |
printf("%d\n",max?2*max:n); //print | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment