#P8040. [COCI 2016/2017 #7] IGRA
[COCI 2016/2017 #7] IGRA
Background
Mirko and Slavko are very bored with their ski trip, so they start playing a new game.
Problem Description
First, Mirko chooses an integer , then Slavko writes down letters, and Mirko writes down a word of length . Slavko needs to use the letters he wrote down to form a word, and in his word, there must be no position where the letter is the same as the letter in the corresponding position of Mirko’s word. To make the game challenging, Mirko also requires that Slavko’s word be the lexicographically smallest among all words that satisfy the requirement. This word is guaranteed to exist. Since Mirko and Slavko are still young, they only know the three letters a, b, and c, so the words they write will also contain only these three letters.
Please help Slavko find such a word.
Input Format
The first line contains an integer , the number of letters in the words written by Mirko and Slavko.
The second line contains a string of length , representing all the letters included in the word written by Slavko.
The third line contains a string of length , representing the word written by Mirko.
Output Format
Output one line with a string of length , the lexicographically smallest string that satisfies the requirement.
For two strings of length , is lexicographically smaller than if and only if there exists an integer such that , , and .
3
abc
abc
bca
4
baba
baab
abba
5
aaabc
abcba
baaac
Hint
Constraints
For of the testdata, .
For all testdata, , and all strings can only contain the letters a, b, c.
Source
This problem comes from COCI 2016-2017 CONTEST 7 T3 IGRA. With the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5