PRFXGD unexpected behaviour

https://www.codechef.com/viewsolution/30815404
can anyone explain whats wrong with my solution of good prefix? test cases are running individually but giving answer as 0 except for the first test case which runs fine every time. plz look as i never experienced anything like that before.

Rewrite the code with following retouch.

if(v[s[i]-97].size()==0){
v[s[i]-97].push_back(s[i]-97);

now its working for sample cases,that is running for all cases together instead of passing individually but still giving WA. can you explain what this retouch do?