Блог пользователя mac_n_cheese_pog

Автор mac_n_cheese_pog, история, 3 года назад, По-английски

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

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

https://pastebin.com/uYSMTEHx

  • Проголосовать: нравится
  • -16
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

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.