Tour Course
Time limit2sMemory limit1024 MB
Given which tourists on a circular route end with affection at least 1, build a snowfield or desert pattern for the N segments, or report NO if none exists.
- Level
Medium7 of 10
- Topics
- Prefix sum, String, Implementation
- Solved
- No attempts yet
Problem
The UCPC Kingdom has a circular tour route made of segments that together cover the whole kingdom. Each segment has a shuttle bus to the next segment. From segment with , you can move to segment , and from segment you can move to segment .
Now tourists from the Arctic will tour the UCPC Kingdom on this route. The -th tourist starts at segment and rides the shuttle buses to tour segments in total.
Each segment is either a snowfield or a desert. Every tourist starts at their starting point with an affection of . Each time they pass a snowfield segment, their affection increases by , and each time they pass a desert segment, it decreases by . If the affection reaches during the tour, the tourist stops immediately and leaves for their home country. After touring all segments, a tourist whose affection is at least buys an expensive souvenir from the UCPC Kingdom and returns home.
You live in the Arctic and know which tourists bought a souvenir. Use that information to work out the structure of the tour route. Given the purchase status of tourists 1 through , print one possible structure of the route.
Output
If a route exists for the given input, print YES on the first line and a string of length on the second line. The -th character is + if segment is a snowfield and - if it is a desert.
If no route exists, print NO on the first line.
Input
The first line contains (). The second line contains a string of length . The -th character is O if tourist bought a souvenir and X if not.