Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

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

1 | Radewoosh | 3443 |

2 | tourist | 3372 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | ksun48 | 3176 |

5 | scott_wu | 3168 |

6 | CongLingDanPaiSh…5 | 3157 |

7 | Benq | 3154 |

8 | Petr | 3139 |

9 | Um_nik | 3138 |

10 | LHiC | 3118 |

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

1 | Radewoosh | 195 |

2 | Errichto | 176 |

3 | rng_58 | 158 |

4 | Ashishgup | 157 |

5 | neal | 156 |

6 | tourist | 154 |

7 | Petr | 151 |

8 | PikMike | 150 |

9 | Um_nik | 149 |

10 | kostka | 147 |

10 | Swistakk | 147 |

10 | Vovuh | 147 |

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/12/2018 07:15:05 (d3).

Desktop version, switch to mobile version.

Supported by

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