Please read the new rule regarding the restriction on the use of AI tools. ×

jmichael's blog

By jmichael, history, 8 months ago, In English

Unexpected TLE with Segment tree

My solution to 1919F1 - Wine Factory (Easy Version) involved a few observations

  1. Since the capacity of pipes are infinite in the easy version, each tank will transfer all remaining water to the next tank, and we can imagine the last tank dumping water outside
  2. Now suppose we can also add water in from the left. How will the water that is dumped out from the right change?
  3. I realized that there is a base amount that will always be dumped. As I starting adding water from the left, there will be initially no change, but after a certain cutoff, the the amount of water dumped will increase.
  4. So a system of water tanks can be characterized by two values — base and cutoff
  5. Also two systems of water tanks can be composed. We can derive the base and cutoff of the larger system.
  6. Using a segment tree, we can exploit this to make updates fast
  7. The total amount of water and wine is conserved.

The logic seems right enough, since it ran till test 10, but encountered a TLE there. However the time complexity is O(n logn) for building the segment tree and O(q logn) for answering the queries. The constant factors also don't seem very large. I made some optimizations (replaced pair <int, int> with array) and tried again without success. What is the cause of this?

My solution

Links to my attempts

Full text and comments »

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

By jmichael, history, 11 months ago, In English

Why isn't there TLE?

I was solving the D problem of the previous contest Div2.907
I used binary search, but it needed ridiculous optimizations before it got accepted, and even then, it was a close call.
I played around for a while trying to make it even closer.
After all a while, I noticed....

That, codeforces forgot what TLE is.

As far as I can make out, this is a supreme example of machine learning that in the future, should be of great service to all competitive programmers worldwide.

I made a last attempt at manufacturing a TLE, unfortunately, I failed to get it. It was very disappointing for me. As a competitive programmer, I thought that though I couldn't get AC all the time, at least I could get TLE, if I wanted. Apparently, even this is beyond my ability.

My Entire Program
The solve() function that should create TLE

These are the links to my last attempts
- 230780232 This submission ran till test 17 before TLE occurred, some kind of self-realisation, maybe?!
- 230780567 My next attempt was totally unsuccessful, it got AC, what a pity.

On my local system, things work as normal. I'm currently expecting to see some output after a few decades.

As these violations of the universe are beyond my sphere of comprehension, could any wise sage possibly enlighten me?

Full text and comments »

Tags tle
  • Vote: I like it
  • +10
  • Vote: I do not like it