| UDESC Selection Contest 2025-1 |
|---|
| Закончено |
Lucas Thomas Anderson used to work in an office and lived a normal life, except for the fact that he was a hacker in his spare time and discovered he is trapped inside an $$$N \times M$$$ matrix! He is currently at cell $$$(1,1)$$$ and, to escape the matrix, he needs to reach Morpheus, who is located at cell $$$(N,M)$$$.
However, Agent Gui also wants to find Morpheus to thwart Thomas's plans before he escapes the matrix. To do this, Gui alters reality, creating a challenge centered around the bitwise OR operation, because Gui knows that although Thomas is an experienced hacker, he is more familiar with other operations.
In this reality altered by Agent Gui, the time anyone takes to walk through a path in the matrix is the bitwise OR of the values in the cells traversed. Also, since Gui is an AI-powered program, he can easily traverse the matrix and find the fastest route to wherever he wants to go.
Now, Agent Gui is at cell $$$(X,Y)$$$ and wants to reach Morpheus before Thomas. Gui is not in the same position as Thomas or Morpheus. Both Gui and Thomas can move from one cell to another if the two share an edge (i.e., up, down, left, or right).
The fate of humanity is in your hands! Given Agent Gui's position and the value of each cell, write a program that tells Thomas the minimum time he can take to reach Morpheus and also the time it would take Gui.
The first line of input contains two integers $$$N$$$ and $$$M$$$ ($$$3 \leq N \cdot M \leq 10^5$$$), the dimensions of the matrix.
The second line contains two integers $$$X$$$ and $$$Y$$$, Agent Gui's position in the matrix.
Next, $$$N$$$ lines follow. The $$$i$$$-th of these lines ($$$1 \leq i \leq N$$$) contains $$$M$$$ values, and the $$$j$$$-th value in it represents the value in cell $$$(i,j)$$$ of the matrix ($$$0 \leq V_{i,j} \leq 2 \cdot 10^9$$$).
It is guaranteed that the values of the cells where Thomas, Gui, and Morpheus are located are $$$0$$$.
Print two values: the time Thomas and Gui take to reach Morpheus.
3 31 30 2 01 5 61 1 0
1 3
3 43 10 2 4 84 8 2 00 2 3 0
6 3
3 43 10 2 3 84 8 2 00 2 4 0
3 6
3 31 20 0 11 1 11 1 0
1 1
| Название |
|---|


