In the recent contest (LTIME62B) I made a brute force solution to solve FRCPRT for 30 points. I submitted my solution 2 times. Only difference I made was in the former one I was scanning the input by β%sβ (i.e. as a whole string) and in the latter one I was scanning it by β%cβ. I got WA in the former one but AC for latter one. Can anyone explain me why I got WA with β%sβ?
It is simple:
%s adds some extra characters than it scanned to indicate the end of a string (\0 for example)
As you donβt reserve space for those extra characters some sort of overflow happens which causes an incorrect answer. I would reserve approximately 5 extra space for each string:
char A[N][M+5];
1 Like
I believe just 1 works fine
but yeah 5 is cool too