Can you optimse my code for the given problem even further ?

Правка en1, от Ryuma_7810, 2024-04-19 10:17:32

Problem: https://mirror.codeforces.com/contest/1937/problem/B (Binary path)

int n;  cin>>n;
string s,t; cin>>s>>t;

int count=1;
string path= s[0] + t;
string min_str= path;

for(int i=1; i<n; i++)
{
    path[i]= s[i];

    if(path < min_str){
        count=1;
        min_str= path;
    }
    else if(path == min_str)
            count++;

}

cout<<min_str<<endl;
cout<<count<<endl;

I have written this coder sample for the above problem, but it keeps on getting TLE on Test 4. I can't seem to understand it because the time complexity for this is O(n) and n<=2.10^5 Can you explain in which part of my code is there an issue ? I want to use this current approach.

Теги c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Ryuma_7810 2024-04-19 10:17:32 771 Initial revision (published)