I am not able to determine, why wasn't my solution accepted, despite being logically correct.

Refer to this Question
I made a submission to this problem by using data types for variables t, n, i, count as int. The submission was rejected.
I changed the data type from int to long int, it got accepted.
Why did this happen. An explain with adequate information will be appreciated!

Submission that got rejected -> Rejected
Submission that got accepted -> Accepted

1 Like

Let’s denote the number of 1’s in the string as c. Then the answer is c*(c+1)/2. Let’s approximate this as c^2. Since, c can be equal to 10^5 in worst case, thus value of c^2 can be 10^{10} in worst case. This exceeds the max value that int can store in C (see), but fits in long int. Thus it causes overflow for int but works for long int.

I hope this answered your question :slight_smile:

//