affiche juste le code, pas d'explications !
- User
System: affiche juste le code, pas d'explications ! User: Tu es un développeur python3 expérimenté, et tu dois concevoir un programme en python (avec des commentaires en français, sans utiliser de librairies externes, sans
if __name__=="__main__":, avec type hints, et en privilégiant les algorythmes a complexité constante (O(1)) et/ou complexité linéaire (O(n))). Le programme va recevoir les données en entrée sur la stdin, et doit répondre sur la stdout. Fabrique moi un programme python qui résout le problème (énoncé en markdown) suivant :Kayak Cross
On the kayak cross race, the water swirls, and the athletes prepare to battle the strength of the currents. As the kayakers focus, a question lingers in your mind: which starting positions could lead to victory if they were only carried by the current?
The kayak racing area is modeled as a grid with
Nrows andMcolumns, with flow directions on each cell:v,>,^,<. Where:vindicates downward flow,>indicates rightward flow,^indicates upward flow,<indicates leftward flow.
Every second, each athlete is carried by the current to the next cell based on the direction of the current on their current position. Collisions between kayakers are ignored.
Athletes start from the first row and reach the finish line by crossing the
N-th row.Some starting positions may not allow reaching the finish line, but there is always at least one position that does.
The current won't push anyone outside the grid, except for crossing the finish line at row
N.Data
Input
Line 1: two integers
NandM, separated by a space, representing the number of rows (6 <=N<= 50) and the number of columns (4 <=M<= 50) of the racing area.The next
Nlines:Mdirections (v,>,^ou<) representing the direction of the current on each cell of the given row.Output
The starting position(s) that allow crossing the finish line first (output them in increasing order, separated by spaces if multiple positions tie for first).
Example 1
For the input:
plaintext - Assistantpython