trouvaille's blog

By trouvaille, history, 8 days ago, In English,

Hi everyone,

For this problem https://codeforces.com/problemset/problem/832/B

I wrote this solution http://codeforces.com/contest/832/submission/66086119 I am not sure why it takes so much time. I read ideal solution and you can see my code is basically a mimic of it, there is nothing crazy i am doing I only solved it successfully after adding the two lines cin.tie(0); ios::sync_with_stdio(0); which i think shoud not affect it pls help me.

Thank

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
8 days ago, # |
  Vote: I like it 0 Vote: I do not like it

also yes there are multiple for loops but those cover the same distance as one for loop (the length of the string) so i am not sure why it is so slow

»
8 days ago, # |
  Vote: I like it +6 Vote: I do not like it

I managed to improve it by 200 ms with using #define endl '\n' and cout.tie(0); if I'm not mistaken, endl flushes the output every time you put it and in this problem there might be so many lines to output which causes your code to get high execution time. By defining endl to be '\n' you just use the normal char endline. 66164232

  • »
    »
    8 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thank you so much for helping. I did not realize that this would make a huge impact but I will definitely remember to use this IO optimizations from now on.

»
8 days ago, # |
  Vote: I like it +10 Vote: I do not like it

You are doing pattern.find('*') in a loop.

  • »
    »
    8 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much for finding this. actually I originally searched the wrong string when answering this question, so when i fixed from "q" to "pattern" i forgot to take it out of the loop.