Idleness limit exceeded codeforces719

In problem F of codeforces round 719 i was using fflush(stdout) due to which i was getting “Idleness limit exceeded on test 1”.during the ongoing round i wasn’t able to solve it but after the round i made a slight change instead of using fflush(stdout) i used cout.flush() and it worked .
I Don’t know the reason why it worked but it was written that fflush(stdout) is for c++.
wrong submission link->Submission #115326611 - Codeforces
AC submission link->Submission #115336786 - Codeforces
can anyone tell me what was the issue.

@st0rmbrk , i have another question , wasn’t the test cases invalid , because as per the problem 1 <= n <= 2*10^5 , but in some test cases n is given as 0 , like in TC 2 , which was 0 1 1 ??

No, that’s actually the binary string and not n

but the problem statement is like this ,
where n is size of the string.

That’s the interaction part.
In the input format, they’ve shown given initial hidden binary string and t value.


That’s what @akshitm16 is saying that n is not there.


actually in every case they are showing hidden array and t which is 1 and k.

1 Like

Ok , now i get it , it was not the input that i was getting from the grader. Thank you @akshitm16 for clearing my doubt.

1 Like

You can use cout << "! " << i << endl instead of cout.flush(). I think because of FAST I/O, fflush(stdout) won’t work. @akshitm16 , can you confirm this?
EDIT: @st0rmbrk , remove the FAST I/O and check again.

1 Like

but why fflush(stdout) was not working when in question it was written that it will work for c++.

got it. @samarth2017 , @st0rmbrk , it was my first interactive problem in CF ( i think ) , so that’s why the confusion.

Yes it worked
Ac link → Submission #115344437 - Codeforces
Any specific reason for that ??.

I think with fast i/o, it gives output after taking all the input but I’m not sure.

1 Like

You can read here, I also don’t know much about it. But in interactive problems, it is better to use “endl”. You won’t get TLE because of that atleast.

1 Like

I dont think so, I used fast i/o and got AC. In interaction problems instead on “\n” use endl always because endl flushes the output immediately but “\n” accumulates everything then prints it. And most of the interactive problems are always binary search or ternary search :rofl:.

1 Like
using namespace std; 

void recurse(int l,int r, int k)
	int mid=l+(r-l)/2;
			cout<<"! "<<l<<endl;
			cout<<"! "<<l+1<<endl;
	cout<<"? "<<l<<" "<<mid<<endl;
	int a;	cin>>a;
int main()
	int n,t,k;
	int l=1,r=n;
	return 0;

This was my working code for it by using fast i/o.

same happened with me, then I used cout.flush(). some users got ac without any of these.

thanks brother, not knowing about such thing. I define endl as “\n” :joy:

Yeah using “endl” is absolutely fine. This post is about using fflush(stdout) with FAST I/O on which @akshitm16 has commented.

1 Like

@st0rmbrkendl” by default performs flush operation.
you can use endl or fflush stdout for flush operation.
You can check my Solution here.
Solution Link
Link to Explanation

1 Like