top of page
Search

Day 3 | Queue at the school | C++

  • Writer: Ayush Mahajan
    Ayush Mahajan
  • Aug 28, 2022
  • 1 min read

Time for our 3rd question. Today we will try to solve: Queue at the school. https://codeforces.com/contest/266/problem/B… Don't forget to try it yourself first.


What I have in mind when I read the question is to actually swap girls and boys as mentioned in the question.


As a competitive programmer, I have one issue in mind is that making changes mentioned in the question takes O(N) times, where N is the length of the string. If we run this for T (number of seconds) times, then it is O(N*T) times.


But if we look at constraints, we see that N*T = 50*50 = 2500 As a rule of thumb, I assume that I can do 100,000,000 operations per second. From this assumption, my code easily runs in under 1 second. Thus, I can move ahead with this approach.


But the question is how do we implement how to do 1 iteration of changes per second mentioned in the question? We can run a for-loop and if a boy is ahead of girl (A[i] == B and A[i+1] == G), then we swap them.


But remember, that if you swap them. Then you won't consider this boy again. So if you swap i and i+1, then you should start checking from i+2 Reason BGG should become GBG But if we go from i to i+1, BGG would become GGB Like here: https://codeforces.com/contest/266/submission/169250731


Again remember, making mistakes is important to learn more things. I learned i and i+2 point by making a mistake only - https://codeforces.com/contest/266/submission/169250701



 
 
 

Comments


bottom of page