__NeverGiveUp__'s blog

By __NeverGiveUp__, history, 4 years ago, In English

what is the problem in this code to get tle?? https://mirror.codeforces.com/contest/1389/submission/102948197

  • Vote: I like it
  • -19
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Although your code is a little hard for me to read, a quick skim shows that you are checking the value of vis[idx][left][flag] but it doesn't seem that you ever set it. This would render your DP useless since you never use the values you memoize.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    maybe, end of main, "visid++" resolve that problem

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Since vis is declared globally, its value will always be zero. However visid starts at 1, and is only changed at the end of main. Honestly I don't see any reason for that increment to be there at all since by that time the answer has already been printed. But it definitely shouldn't changing the behavior of the program that is executed before that statement.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Oh, I was mistaken for something. Now I understand. thank you

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yes thanks alot i just put vis[idx][left][flag]=visid; and i got it ac