PAST3K
PAST3K
A problem where there are multiple boxes with multiple numbers on multiple desks and you have to move them here and there according to the commands.
There are 200,000 desks, 200,000 boxes, and 200,000 orders.
If the execution of a single instruction is not light enough, the time will be exceeded.
Using Python lists in an array-like fashion to create a list of data structure meanings. linked list. This is because I was afraid of running out of time due to overhead if I did it normally with objects and references, and also because I thought it was just a difference in the appearance of the code and not essentially the same.
We have four arrays of length N+1, meaning "the bottom box of box i", "the top box of box i", "the bottom box of desk i", and "the top box of desk i", respectively.
N+1 because the problem condition is 1-origin.
We created a situation where we could use it without worrying about it rather than inputting and outputting one shift without making a mistake.
And I can use 0 to mean null.
Problem E didn't do that, so it needs to be displaced in four places.
Prepare a function that displays a clear indication for debugging purposes, and implement the rest in a straightforward manner.
code:python
def debugPrint():
blocks = [[] for i in range(N + 1)]
for table in range(1, N + 1):
while cur:
for table in range(Q):
# print(frm, to, x)
if p > 0:
else:
# x is first block of TO
else:
# x is last block
else:
# x is first block of TO
# print(prev)
# print(next)
# print(top)
# print(bottom)
# debugPrint()
# print()
for table in range(1, N + 1):
while cur:
for i in range(1, N + 1):
Reading other people's code, it seems that this doesn't need to be a two-way list here, just a list of the top of the desk and the bottom of the box
---
This page is auto-translated from /nishio/PAST3K. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.