### trouvaille's blog

By trouvaille, history, 8 days ago, ,

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

• 0

 » 8 days ago, # |   0 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, # |   +6 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, # ^ |   0 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, # |   +10 You are doing pattern.find('*') in a loop.
•  » » 8 days ago, # ^ |   0 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.