1335E2 - Three Blocks Palindrome (hard version)

In this problem, the solution outlined by the editorial is $$$O(n*200*200)$$$, here $$$N$$$ <= $$$200000$$$.

How is the solution able to pass with that time complexity on a constraint like this?

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

1 | tourist | 3619 |

2 | Um_nik | 3493 |

3 | ecnerwala | 3446 |

4 | Radewoosh | 3383 |

5 | ksun48 | 3357 |

6 | yosupo | 3324 |

7 | Benq | 3299 |

8 | maroonrk | 3243 |

9 | apiadu | 3238 |

10 | Petr | 3217 |

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

1 | Errichto | 207 |

2 | Monogon | 199 |

3 | SecondThread | 195 |

4 | vovuh | 189 |

5 | antontrygubO_o | 186 |

5 | Um_nik | 186 |

7 | pikmike | 184 |

8 | Ashishgup | 182 |

9 | pashka | 169 |

10 | Radewoosh | 167 |

1335E2 - Three Blocks Palindrome (hard version)

In this problem, the solution outlined by the editorial is $$$O(n*200*200)$$$, here $$$N$$$ <= $$$200000$$$.

How is the solution able to pass with that time complexity on a constraint like this?

↑

↓

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/26/2020 13:13:18 (f3).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

You pick a number (for first and third block) and iterate on its positions. Irregardless of the 'number' of numbers, there are only N positions in total to pick, thus the complexity is

`O(N * 200)`

. Of course you have to implement it in an appropriate way. Similar to how, when you DFS/BFS, you iterate on the children of a node, and you do it for every node! It seems`O(N^2)`

but there are only N distinct nodes to visit in total.