majay1638's blog

By majay1638, history, 6 weeks ago, In English

Hi guys, I am trying to solve segment tree question on cses . my Python solution passes only 1 test case and gives me TLE, but c++ solution get accepted, i tried to look online optimize python solution but still no luck , if you can help me to optimize my code it would be great .

problem : https://cses.fi/problemset/task/1648

My code Link : code link

Thanks

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

»
6 weeks ago, # |
  Vote: I like it -8 Vote: I do not like it

Hi! I suggest you to keep solving problems in C++. Python is squite slower and Time Limit in CSES is quite tight. I don´t know python very much but you one thing you can try, is to find any other method to read input and print output faster. There are lots of queries and that could be the cause.

In addition, I can see that most of people solved this problem in C++, and only few people solve in Python with best execution time of 0.8 seconds.

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks for the suggestion Monazo1997 , actually i'm new to CP world and i use Python for web development projects that's why it is hard for me to learn 2 language at the same time but let's see till where python can lead me :)

»
6 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it