This is because source limit is 50000B.
You canāt submit a program having more than 50000 characters.
Probably the system react on such submissions in such weird way.
Hence in this problem such cheat with storing primes in the code is not possible.
Thanks for spending time to look into the code.
As suggested, I replaced queue with usual array. But now I get a runtime error.
Now what could be reason for this.
It is quite hard to follow your code.
Try to combine two cases odd and even.
Clearly we could do check like server[hackX[k]][hackY[k]+1]%2 == server[i][j]%2
so that code for bfs will be only one time in the solution.
Also why donāt you declare int x=hackX[k], y=hackY[k]
and use them everywhere?
It will simplifiy a code drastically.
I made all the suggested improvements. The code looks less cumbersome now.
Also, the code for BFS is written only once. Instead of using a separate matrix to store the visited nodes, I make the value of node to -1 when it is visited. That helps me to preserve memory. I hope that would clarify my approach.
Still I get runtime error. I am puzzled. Could you help me please?
You should mark server[x][y-1] = -1 when you add (x,y-1) to hackX, hackY. Otherwise you could add the same cell several times. Probably this is also the reason of TLE for bfs with queue. Maybe fixing this in the first submission will make it faster.
For example. You have (0,0), then you add (0,1) and (1,0) and then when you consider (0,1) you add (1,1) but not mark it, hence when you consider (1,0) you will add (1,1) again.
So the reason of RE is that you add more than 350^2 elements in all.
@anton_lunyov: First of all thanks for your feedback, as for the two test cases that you gave, AFAIK my solution will return 6 and 52 respectively which is correct, and as for the complexity well i am not sure what is the correct answer specially i donāt know what is the worst case to get roots of the two paths, but what i can tell you is that it will only take O(n**2) for the last test case that you gave, finding the roots will be only O(1) (2 extra iteration at max).
Its just for testing ā1ā at place (1,1)ā¦
Got my mistakeā¦
its a silly one in function kr1(int,int)ā¦wrote pass[i][j] instead of typ[i]][j]ā¦
damn shitā¦