Why is this leading to TLE?

Revision en1, by Agniva_, 2024-04-01 10:16:06

Problem Link 254383531

void solve(){
   int n; cin>>n;
   vi v(n); rep(i,0,n) cin>>v[i];
   int flag=1;
   rep(i,0,n/2){
     if(v[i]!=v[n-1-i]) {
        flag=0; break;
     }
   } 
   if(flag){
    yes
    return;
   }
   string s="";
   for(int i=0;i<n;i++) 
     if(v[i]!=v[0]) s=s+to_string(v[i]);
    string s2=s;
    reverse(s2.begin(),s2.end());
    if(s==s2) 
    {
        yes return;
    }
    s="";
    for(int i=0;i<n;i++) 
     if(v[i]!=v[n-1]) s=s+to_string(v[i]);
    s2=s;
    reverse(s2.begin(),s2.end());
    if(s==s2) 
    {
        yes return;
    }
    no 
}
Tags strings, to_string

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Agniva_ 2024-04-01 10:16:06 727 Initial revision (published)