A7999 | Title
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containing at least once each of the first $k$ Latin letters and not containing any other ones. Also, the title should be a palindrome, that is it should be read similarly from the left to the right and from the right to the left.
Vasya has already composed the approximate variant of the title. You are given the title template $s$ consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.
Vasya has already composed the approximate variant of the title. You are given the title template $s$ consisting of lowercase Latin letters and question marks. Your task is to replace all the question marks by lowercase Latin letters so that the resulting word satisfies the requirements, described above. Each question mark should be replaced by exactly one letter, it is not allowed to delete characters or add new ones to the template. If there are several suitable titles, choose the first in the alphabetical order, for Vasya's book to appear as early as possible in all the catalogues.
输入格式
The first line contains an integer $k$ ( $1<=k<=26$ ) which is the number of allowed alphabet letters. The second line contains $s$ which is the given template. In $s$ only the first $k$ lowercase letters of Latin alphabet and question marks can be present, the length of $s$ is from 1 to 100 characters inclusively.
输出格式
If there is no solution, print IMPOSSIBLE. Otherwise, a single line should contain the required title, satisfying the given template. The title should be a palindrome and it can only contain the first $k$ letters of the Latin alphabet. At that, each of those $k$ letters must be present at least once. If there are several suitable titles, print the lexicographically minimal one.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line $a$ is lexicographically smaller than the line $b$ , if exists such an $i$ ( $1<=i<=|s|$ ), that $a_{i} < b_{i}$ , and for any $j$ ( $1<=j<i$ ) $a_{j}=b_{j}$ . $|s|$ stands for the length of the given template.
The lexicographical comparison is performed by the standard < operator in modern programming languages. The line $a$ is lexicographically smaller than the line $b$ , if exists such an $i$ ( $1<=i<=|s|$ ), that $a_{i} < b_{i}$ , and for any $j$ ( $1<=j<i$ ) $a_{j}=b_{j}$ . $|s|$ stands for the length of the given template.
输入输出样例
输入 #1
3 a?c
输出 #1
IMPOSSIBLE
输入 #2
2 a??a
输出 #2
abba
输入 #3
2 ?b?a
输出 #3
abba
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted