mac_n_cheese_pog's blog

By mac_n_cheese_pog, history, 3 years ago, In English

u guys said i need to train,so i train.but i cant do this.thus,help me out.

https://codeforces.me/problemset/problem/1146/B

https://pastebin.com/uYSMTEHx

  • Vote: I like it
  • -16
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

You should at least try to explain your solution method, so that we don't need to look at the code and try to understand it.

Also, something like s.erase(s.begin()+i); is $$$O(N)$$$ worst case. Instead, keep another string t and add the character to t where you don't erase it in s (because adding a char to the end of a string is $$$O(1)$$$ amortized).

So instead of this:

if (CONDITION) {
    s.erase(s.begin()+i);
}

Do this:

if (!CONDITION) {
    t += s[i];
}

and then use t instead of s.