Time complexity analysis

Revision en1, by NafisAlam, 2023-05-18 19:22:32

Need help figuring out why this code is getting TLE. Problem link : 1829D - Gold Rush

void solve1829D()
{
   int n, m, cnt = 0;
   cin >> n >> m;
   set<int> st;
   st.insert(n);
   while(st.size() > 0)
   {
      if(st.find(m) != st.end())
      {
         cout << "YES" << endl;
         return;
      }
      int x = *st.begin();
      st.erase(st.begin());
      if(x % 3 == 0) {st.insert(x / 3); st.insert((x * 2) / 3);}
   }
   cout << "NO" << endl;
}
Tags time complexity, time limit exceeded

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English NafisAlam 2023-05-18 19:22:32 523 Initial revision (published)