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

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

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
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +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 ^_^

  • »
    »
    3 года назад, # ^ |
    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

»
4 месяца назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hey can anyone tell me what is wrong with my code? code:https://cses.fi/paste/40be0ebd00f6670b964b3d/![ ](https://i.imgur.com/s5JhwIp.png) my code is giving wa on thes test cases :