meirbekbolatbekov002's blog

By meirbekbolatbekov002, history, 3 years ago, In English

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

| Write comment?
»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

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 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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 :