Spilled Ink
Time limit1sMemory limit512 MB
Given a string with hidden letters (#) and its Z-array, restore a string that matches both, or report that no such string exists.
- Level
Medium7 of 10
- Topics
- String, Union-find, String matching
- Solved
- No attempts yet
문제
Didi defines for a string of uppercase letters (A-Z) as the length of the longest common prefix of and the suffix of . Didi built the array from these values using an algorithm found after long study. While dancing with joy, Didi spilled ink on part of the string , so Didi cannot check whether the array is correct.
The kind ryute wants to help the desperate Didi. Using the partially hidden string and the array that Didi wrote, ryute will restore the original string . ryute will also check whether Didi's array is correct. If at least one possible original string exists, the array is considered correct. Otherwise, it is considered incorrect. Help ryute and Didi.
입력
The first line contains the length of the string ().
The second line contains the string . consists of uppercase letters (A-Z) and #. A # means the letter at that position is hidden by ink. There are at most 20 # characters.
The third line contains the elements () of the array that Didi wrote, separated by spaces, in order.
출력
If the array that Didi wrote is incorrect, print THINKINGFACE. Otherwise, print YES on the first line and the original string on the second line. If several strings are possible for , print any one of them.