CHEFSHIP TLE in May - CookOff 2020

Why am I Getting TLE in Below Question in May Cook-Off?

Question Link (CHEFSHIP) :

https://www.codechef.com/COOK118B/problems/CHEFSHIP/

My Solution :

1.) https://www.codechef.com/viewsolution/33310994

2.) https://www.codechef.com/viewsolution/33309136

std::string::compare() does, a linear scan to check if two strings match. So the time complexity of this submission is O(N^2).

Okay! Thanks for Suggesting!