← Back to topics
Topic

z-carousel

m
msantl
How can i speed things up ?

http://www.z-trening.com/submit.php?subm_stat=1&submit=7100064111
i
iggy91
I don't know your idea, but the basic thing is that you shouldn't make all rotation specified in the task, but only % 4...

Imagine you make 4 clockwise rotations. It is the same as making no rotations at all. Maybe that's the reason of TLE in your code.
d
dejandenib
Can you explain your idea?
m
msantl
I count all rotations for each platform, and when i add to some platform new number of rotations i mod this number with 4 .

After all rotations are saved in an array , i go from 1. platform to last ( n/2 ). I have 3 functions ( one for 90' , 180', and 270').

When i reach some platform and number of rotations is not 0, i rotate it. When i rotate i save new positions of numbers in one array (i output this one) , and also to another one (which is only here for reading out of it for rotations). I read the info for rotations out of a third array. Now 1. array is for output, but i am swaping 2. and 3. (not whole , just a index which is showing which is for reading , and which for writing) .

If something isn't clear i can explain it.
d
dejandenib
When i rotate i save new positions of numbers in one array (i output this one) , and also to another one (which is only here for reading out of it for rotations)

You need only two matrices: one for reading input, and the second is the one you will output. The rotating, the translating should be direct from the first matrix to the second. If you're using another array, to copy the elements from the first and then translate to the second, you can realize this is making it 2 times slower. This you can speed up
m
msantl
If i use 2 matrices (and if i don't change this one from which i am reading ) , then i have to add to each platform number of rotations of previous platforms, and then rotate this sum %4 ?
m
msantl
then what am i doing wrong ?
http://www.z-trening.com/submit.php?subm_stat=1&submit=7100064689
d
dejandenib
I've tested your program on the third test case and as i see your program makes a mistake when there is no rotation at all on a platform
m
msantl
i really don't know what's wrong. i tested this code with several test cases (with and without rotations), on several computers and it seems ok.
d
dejandenib
I've tested your program on the 4th test case and you really do have a bug. But this time in this test case it appears when there is a rotation.
m
msantl
i found my bug, but i still get TLE

http://www.z-trening.com/submit.php?subm_stat=1&submit=7100064806


How do you rotate ,whole sub-matrices or just 2 rows and 2 columns needed ?

@admin , i am sorry for submitting code which wrote to a file ( i forgot to change before submitting)
m
msantl
Finally i managed to solve it. Thanks for your help, i really appreciate it.