Anyone help me out don't know why getting RTE

https://www.codechef.com/viewsolution/37968909

1 Like

In the function solve u have used boost.Hence for each test case boost is getting called and giving run time error.Call boost in the main function before the while loop and not in the solve function.

https://www.codechef.com/viewsolution/37981314
Even with out using boost i’m getting RTE

any one help me

For the string a, just take input as cin>>a. If you want to take input via loop, declare a character array as char a[n].

Go for the editorial

@hydro_ly_te CodeChef: Practical coding for everyone
thanks for your help but getting TLE

The constraint on N is 10^5, so running nested loop will definitely give TLE. The most simple way to do is, to count the total 1's in the string i Then the total substrings which will start and end with 1 will be (count)*(count+1)/2 i.e. taking every pair of 1’s present in the string.
Pseduo code:

        int c = count(str.begin(),str.end(),'1');
        cout << c * (c+1)/2 <<endl;
1 Like

@hydro_ly_te thanks for your greedy solution.
but i have a doubt: is length() function a constant time function.

int count=0;
for(int i=0;i<n;i++) {
if(s.charAt(i)==‘1’) {
count++;
}
}
int ans=(count*(count+1))/2;
return ans;

use this hope it will worked…

Yes constant time, O(1) time complexity