Compute the total time for an orb starting on each tile of a corridor to escape.
A linear corridor of n tiles, numbered 1 to n. Each tile i has a direction s[i], either '<' (left) or '>' (right), and a nonnegative integer hardness cost c[i]. An orb placed on tile i immediately accumulates time c[i], then tile i flips its direction ('<' becomes '>' and vice versa), then the orb moves one tile in the direction tile i had before it was flipped. This repeats until the orb leaves the corridor, landing at position 0 or n+1.
Answer n independent queries: for every starting position i (1 <= i <= n), compute the total time (sum of hardness costs of visited tiles) until the orb escapes. The corridor resets to its initial directions before each query.
Input: line 1 is n; line 2 is a string s of length n of '<' and '>'; line 3 is n space-separated integers c1 ... cn.
Format · Online assessment.
Community answers
Related questions
Compute the total size of a file or directory in a directory tree.Related courses


