CHEFSHIP TLE in May - CookOff 2020

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

Question Link (CHEFSHIP) :

My Solution :

1.) CodeChef: Practical coding for everyone

2.) CodeChef: Practical coding for everyone

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!