Skip to content

Instantly share code, notes, and snippets.

@officialcjunior
Created March 24, 2020 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save officialcjunior/da93d5e7dfc5f84490e8d41f95897161 to your computer and use it in GitHub Desktop.
Save officialcjunior/da93d5e7dfc5f84490e8d41f95897161 to your computer and use it in GitHub Desktop.
Solution to 1244B of the codeforces problemset
#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