A10058 | New Language
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Living in Byteland was good enough to begin with, but the good king decided to please his subjects and to introduce a national language. He gathered the best of wise men, and sent an expedition to faraway countries, so that they would find out all about how a language should be designed.
After some time, the wise men returned from the trip even wiser. They locked up for six months in the dining room, after which they said to the king: "there are a lot of different languages, but almost all of them have letters that are divided into vowels and consonants; in a word, vowels and consonants must be combined correctly."
There are very many rules, all of them have exceptions, but our language will be deprived of such defects! We propose to introduce a set of formal rules of combining vowels and consonants, and include in the language all the words that satisfy them.
The rules of composing words are:
- The letters are divided into vowels and consonants in some certain way;
- All words have a length of exactly $n$ ;
- There are $m$ rules of the form ( $pos_{1},t_{1},pos_{2},t_{2}$ ). Each rule is: if the position $pos_{1}$ has a letter of type $t_{1}$ , then the position $pos_{2}$ has a letter of type $t_{2}$ .
You are given some string $s$ of length $n$ , it is not necessarily a correct word of the new language. Among all the words of the language that lexicographically not smaller than the string $s$ , find the minimal one in lexicographic order.
After some time, the wise men returned from the trip even wiser. They locked up for six months in the dining room, after which they said to the king: "there are a lot of different languages, but almost all of them have letters that are divided into vowels and consonants; in a word, vowels and consonants must be combined correctly."
There are very many rules, all of them have exceptions, but our language will be deprived of such defects! We propose to introduce a set of formal rules of combining vowels and consonants, and include in the language all the words that satisfy them.
The rules of composing words are:
- The letters are divided into vowels and consonants in some certain way;
- All words have a length of exactly $n$ ;
- There are $m$ rules of the form ( $pos_{1},t_{1},pos_{2},t_{2}$ ). Each rule is: if the position $pos_{1}$ has a letter of type $t_{1}$ , then the position $pos_{2}$ has a letter of type $t_{2}$ .
You are given some string $s$ of length $n$ , it is not necessarily a correct word of the new language. Among all the words of the language that lexicographically not smaller than the string $s$ , find the minimal one in lexicographic order.
输入格式
The first line contains a single line consisting of letters 'V' (Vowel) and 'C' (Consonant), determining which letters are vowels and which letters are consonants. The length of this string $l$ is the size of the alphabet of the new language ( $1<=l<=26$ ). The first $l$ letters of the English alphabet are used as the letters of the alphabet of the new language. If the $i$ -th character of the string equals to 'V', then the corresponding letter is a vowel, otherwise it is a consonant.
The second line contains two integers $n$ , $m$ ( $1<=n<=200$ , $0<=m<=4n(n-1)$ ) — the number of letters in a single word and the number of rules, correspondingly.
Next $m$ lines describe $m$ rules of the language in the following format: $pos_{1},t_{1},pos_{2},t_{2}$ ( $1<=pos_{1},pos_{2}<=n$ , $pos_{1}≠pos_{2}$ , $t_1,t_2 \in \{V,C\}$ ).
The last line contains string $s$ of length $n$ , consisting of the first $l$ small letters of the English alphabet.
It is guaranteed that no two rules are the same.
The second line contains two integers $n$ , $m$ ( $1<=n<=200$ , $0<=m<=4n(n-1)$ ) — the number of letters in a single word and the number of rules, correspondingly.
Next $m$ lines describe $m$ rules of the language in the following format: $pos_{1},t_{1},pos_{2},t_{2}$ ( $1<=pos_{1},pos_{2}<=n$ , $pos_{1}≠pos_{2}$ , $t_1,t_2 \in \{V,C\}$ ).
The last line contains string $s$ of length $n$ , consisting of the first $l$ small letters of the English alphabet.
It is guaranteed that no two rules are the same.
输出格式
Print a smallest word of a language that is lexicographically not smaller than $s$ . If such words does not exist (for example, if the language has no words at all), print "-1" (without the quotes).
输入输出样例
输入 #1
VC 2 1 1 V 2 C aa
输出 #1
ab
输入 #2
VC 2 1 1 C 2 V bb
输出 #2
-1
输入 #3
VCC 4 3 1 C 2 V 2 C 3 V 3 V 4 V abac
输出 #3
acaa
In the first test word "aa" is not a word of the language, but word "ab" is.
In the second test out of all four possibilities only word "bb" is not a word of a language, but all other words are lexicographically less, so there is no answer.
In the third test, due to the last rule, "abac" doesn't belong to the language ("a" is a vowel, "c" is a consonant). The only word with prefix "ab" that meets the given rules is "abaa". But it is less than "abac", so the answer will be "acaa"
In the second test out of all four possibilities only word "bb" is not a word of a language, but all other words are lexicographically less, so there is no answer.
In the third test, due to the last rule, "abac" doesn't belong to the language ("a" is a vowel, "c" is a consonant). The only word with prefix "ab" that meets the given rules is "abaa". But it is less than "abac", so the answer will be "acaa"
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted