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
1 Like