A higher resolution is required to access the IDE
- 121
Statement
Goal
You're riding a roller coaster track, starting on the left and stopping on the right… or somewhere in the middle, if you run out of inertia !A roller coaster is composed of several tracks in an ASCII form : horizontal tracks (underscores
In this puzzle, every roller coaster is well formed :
- It starts and ends with a horizontal track.
- It is not broken, i.e. every ascii column has one and only one track, and tracks are correctly aligned.
- It has no V-sink
Your goal is to tell in which position your wagon will stop (counted from
• Your wagon starts on the first track with a given starting inertia.
• At the beginning of each turn, your inertia will change depending on the track your wagon is on :
- A horizontal track
- A descending track
- An ascending track
• If your inertia goes negative, your wagon changes direction (switching back your inertia to its absolute value and reversing ascending and descending tracks).
• After the inertia update, your wagon will move to the next track in its current direction. Null inertia implies staying in place.
• If your wagon reaches the last track or comes back to the first one, it stops there immediately.
• A wagon on a horizontal track with an inertia of
Keep in mind that if your wagon's inertia reaches
Example 0:
Your wagon enters a fully-horizontal track on position
Example 1 :
Your wagon is on an ascending track
Example 2 :
Your wagon is on an ascending track
Example 3 :
Your wagon is on an ascending track
Input
inertia : the starting inertia of your wagon
W H : the width and height of the roller coaster
Next H lines : the ASCII roller coaster
W H : the width and height of the roller coaster
Next H lines : the ASCII roller coaster
Output
An integer i giving the 0 -based track position where your wagon will stop.
Constraints
0 < inertia < 100
0 < W, H < 100
0 < W, H < 100
Example
Input
2 8 4 _....... .\....._ ..\.../. ...\_/..
Output
7
A higher resolution is required to access the IDE