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

Автор meirbekbolatbekov002, история, 5 лет назад, По-английски

This code passes majority of testcases on CSES.fi except the ones from 6-9 for which I keep getting TLE. Tried many times, but could not fix it. Any hints?

Link to the problem

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

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

SOLVED! But anyway, I want to know on which part you'd possibly make optimizations.. In case your method differs with mine it might be a pretty useful insight to know ^_^

  • »
    »
    5 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    String concatenation may take a lot of time, as it copies the whole string a, add a char, then write the resulting string to a (This actually depends on some factor, such as the language, compiler, etc, I dont really understand about that too). Instead of building the string ans, you can decide whether an answer exist (the d value in your code) and if it does, print the output as you go through the array cnt[] twice, one for the first half of the answer, and the other for the second half.

    Relevant blog : https://mirror.codeforces.com/blog/entry/94701

    Edit : Added a link to relevant blog