First Solved, Last Coded
InterviewTime limit2sMemory limit1024 MB
Given sequences a and b, find push and pop actions on a stack that turn a into b, or report NO if impossible.
- Level
Medium4 of 10
- Topics
- Stack, Greedy, Simulation
- Solved
- No attempts yet
문제
In ICPC, teamwork is everything. That is why everyone on your team has a well-defined role: Sol the Solver can solve any problem in the problem set, Codie the Coder can implement any solution that Sol comes up with, and you are the glue that holds everything together. Sol and Codie are very picky about the order in which they solve and code problems, and your job is to satisfy their preferences.
There will be problems in the upcoming contest, and you know the general topic of each problem: greedy, geometry, graphs, and so on. For simplicity, each topic is represented by an integer from to . These integers do not have to be distinct, so multiple problems can share the same topic.
Sol wants to solve problems in a specific order of topics: first the problem with topic , then the problem with topic , and so on, and finally the problem with topic . Codie has a preference list and will only code problems in that order of topics.
Your job during the contest is to take solution sheets from Sol and hand them to Codie in the correct order. Your team has only one table, so there is not enough space to arrange all solutions neatly. Instead, you follow this workflow: you ask Sol for solutions (who hands them to you in order ), store them in a stack on your part of the table, and hand them to Codie in order .
Formally, at any moment you can take one of two actions:
- If unsolved problems remain, ask Sol for another solution and put it on top of your stack. This action is denoted by the character "S".
- If your stack is not empty, take the solution sheet from the top of the stack and give it to Codie. This action is denoted by the character "C".
For the given preference lists, find a sequence of actions that ensures all problems are solved and coded in the correct order. Assume that solving and coding take no time.
입력
If the task is impossible, print "NO". Otherwise, print "YES" on the first line, followed by the sequence of actions on the second line: a string of characters "S" or "C" ( of each), describing your actions in order.
You may not ask Sol for more solutions after all problems have been solved, and you may not give Codie a solution with the wrong topic. If there are multiple answers, print any of them.