# | User | Rating |
---|---|---|

1 | tourist | 3496 |

2 | Um_nik | 3337 |

3 | Petr | 3298 |

4 | W4yneb0t | 3218 |

5 | Radewoosh | 3216 |

6 | OO0OOO00O0OOO0O0…O | 3188 |

7 | Syloviaely | 3168 |

8 | izrak | 3109 |

9 | anta | 3106 |

10 | fateice | 3099 |

# | User | Contrib. |
---|---|---|

1 | tourist | 184 |

2 | rng_58 | 170 |

3 | csacademy | 165 |

4 | Petr | 158 |

5 | Swistakk | 154 |

6 | lewin | 149 |

7 | Errichto | 147 |

8 | matthew99 | 146 |

9 | adamant | 141 |

9 | Zlobober | 141 |

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/24/2018 22:34:40 (d3).

Desktop version, switch to mobile version.

User lists

Name |
---|

Consider input 00000... 0011... 11111. Do you see why your algorithm has quadratic time complexity?

Sorry I am new to this coding I don't know what is a time complexity

Well basically if some algorithm has time complexity

O(x) that means it does amount of basic actions (like adding, subtracting, indexing an array, etc.) that is proportional toxin worst case wherexis some function of input size.For example, if we say

nis the size of input string of 0's and 1's, then your solution's time complexity isO(n^{2}) because if the answer is 0 it has to remove "01" or "10"n/ 2 times and each removal is done by rebuilding the whole string so it also takesnactions for the first time,n- 2 for the second,n- 4 for the third and so on, which is roughlyn^{2}/ 4 if summed up (it's actually more). So your solution's amount of basic actions in the worst case is 0.25 *n^{2}, which is linearly proportional ton^{2}, so its time complexity isO(n^{2}).So, n's maximum value in the problem is 2 * 10

^{5}, and your solution does 0.25 *n^{2}in the worst case, so your worst case is 10^{10}actions, which is impossible to squeeze into one second (moreover, on C#).I'm not an expert (though my rank states so), but I can say C# can easily do 10

^{6}actions in one second, so probably you should find a solution which time complexity isO(n) so it does about 10^{5}actions and maybe a little more.UPD: in competitive programming, algorithm's time complexity usually very well represents its speed. In other words, if you plug in your maximum values for input size variables in time complexity's function and see that the number you get is about 10

^{6}or less, then you're good to go and your solution will probably pass the time limit. Very rare are cases in which that does not work, because if you came up with a solution which time complexity is the same as the problem's real full solution, then these two are probably the same (and are easiest to come up with)Thank you so much I will study it