Since many days i was trying to understand the logic of problem FATCHEF and today after understanding different situations of input i again made a code for this problem and it is rejected by grader.
Please help me to find the bug as i tried a lot by generating own test cases but it gives correct output for all randomly generated test cases.
Please Help
Codechef submission link : http://www.codechef.com/viewsolution/5243283
Ideone submission link [ with 3 random test cases ] : http://ideone.com/MrwbwY
You know what, Try not to use getchar_unlocked. Use cin , cout or whatever. Even i wanted to do it with fast i/o but it failed always with getchar_unlocked(). I am not telling that it is the reason. But it might be the reason, as it was in my case.
1 Like
okay @pranjalranjan…
I’ll check whether that;s the actual problem… and Thanks…
Just see and comment it out. Then i’ll look into your code. Lazy, u knw
2 Likes
You are not changing the value of pre if array[i]=ch thats why it is giving WA.Try adding this line
else if ( (int)array[i]>=65 && (int)array[i]<=90 && array[i]==ch) prev=i; you’ll get AC :).
2 Likes
Bro you are too awesome!!!
Solution Accepted!! Thanks Bro Thanks a ton!!!
Yahh i know…
btw i was also feeling lazy at that time… So i didn’t tried cin and cout…
But the actual problem was that not adding else if statement which @irshsay321 has commented.
@pranjalranjan
Btw can we consider cin and cout as fast io ?
According to speed: getchar_unlocked()> getchar() >scanf() >cin … cin is the slowest I/O method among these… you can use scanf instead for faster performance. But if there is a small number of input, cin can be used.
2 Likes
Actually you can speed up cin and cout by adding this line std::ios::sync_with_stdio(false); below the int main () line of your code. It makes them faster than scanf and printf.
2 Likes
Is it really true that cin/cout can be made much faster than scanf/printf?because i too have read about this,just wanna know is there an observed difference in i/o speed?