A16369 | Tricky Template
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an integer $n$ and three strings $a, b, c$ , each consisting of $n$ lowercase Latin letters.
Let a template be a string $t$ consisting of $n$ lowercase and/or uppercase Latin letters. The string $s$ matches the template $t$ if the following conditions hold for all $i$ from $1$ to $n$ :
- if the $i$ -th letter of the template is lowercase, then $s_i$ must be the same as $t_i$ ;
- if the $i$ -th letter of the template is uppercase, then $s_i$ must be different from the lowercase version of $t_i$ . For example, if there is a letter 'A' in the template, you cannot use the letter 'a' in the corresponding position of the string.
Accordingly, the string doesn't match the template if the condition doesn't hold for at least one $i$ .
Determine whether there exists a template $t$ such that the strings $a$ and $b$ match it, while the string $c$ does not.
Let a template be a string $t$ consisting of $n$ lowercase and/or uppercase Latin letters. The string $s$ matches the template $t$ if the following conditions hold for all $i$ from $1$ to $n$ :
- if the $i$ -th letter of the template is lowercase, then $s_i$ must be the same as $t_i$ ;
- if the $i$ -th letter of the template is uppercase, then $s_i$ must be different from the lowercase version of $t_i$ . For example, if there is a letter 'A' in the template, you cannot use the letter 'a' in the corresponding position of the string.
Accordingly, the string doesn't match the template if the condition doesn't hold for at least one $i$ .
Determine whether there exists a template $t$ such that the strings $a$ and $b$ match it, while the string $c$ does not.
输入格式
The first line contains an integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases.
The first line of each test case contains an integer $n$ ( $1 \le n \le 20$ ) — the length of the given strings.
The next three lines contain the strings $a, b$ and $c$ . Each string consists of exactly $n$ lowercase Latin letters.
The first line of each test case contains an integer $n$ ( $1 \le n \le 20$ ) — the length of the given strings.
The next three lines contain the strings $a, b$ and $c$ . Each string consists of exactly $n$ lowercase Latin letters.
输出格式
For each testcase, print "YES" if there exists a template $t$ such that the strings $a$ and $b$ match it, while the string $c$ does not. Otherwise, print "NO".
输入输出样例
输入 #1
4 1 a b c 2 aa bb aa 10 mathforces luckforces adhoccoder 3 acc abd abc
输出 #1
YES NO YES NO
In the first test case, you can use the template "C". The first letter of strings $a$ and $b$ differ from 'c', so they match the template. The first letter of string $c$ equals 'c', so it doesn't match.
In the third test case, you can use the template "CODEforces".
In the third test case, you can use the template "CODEforces".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted