I travel from leaves to root and used KMP to find string pattern in my program.
When I used cin in line 46 I get expected output
Link: http://ideone.com/By0PQu
But since it is clearly mentioned in question using cin will give TLE I get 4 TLE in 2nd Subtask
Solution Link: https://www.codechef.com/viewsolution/13891213
So I used scanf instead of cin in line 45 but I get runtime error or all zeros in output
Link: http://ideone.com/3DEx7V
Problem Link : https://www.codechef.com/LOCMAY17/problems/VTREE
Actually after reading the string your code was reading the newline as the character in ta. So, ta[0] was actually a newline which was giving you the runtime error. What I did in your code is that I made a dummy variable “ccc” and read the newline before it entered the loop to input the character. This solved the problem
Code: http://ideone.com/ePBE8n
Actually, one piece of advice would be to use cin and cout only but the the following lines of code just in the beginning of main function for fast I/O.
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Hope this helped
1 Like
what is wrong with this solution , just giving wa in 1 testcase??
https://www.codechef.com/viewsolution/13906095