A14984 | Infinite Replacement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ , consisting only of Latin letters 'a', and a string $t$ , consisting of lowercase Latin letters.
In one move, you can replace any letter 'a' in the string $s$ with a string $t$ . Note that after the replacement string $s$ might contain letters other than 'a'.
You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
Two strings are considered different if they have different length, or they differ at some index.
In one move, you can replace any letter 'a' in the string $s$ with a string $t$ . Note that after the replacement string $s$ might contain letters other than 'a'.
You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
Two strings are considered different if they have different length, or they differ at some index.
输入格式
The first line contains a single integer $q$ ( $1 \le q \le 10^4$ ) — the number of testcases.
The first line of each testcase contains a non-empty string $s$ , consisting only of Latin letters 'a'. The length of $s$ doesn't exceed $50$ .
The second line contains a non-empty string $t$ , consisting of lowercase Latin letters. The length of $t$ doesn't exceed $50$ .
The first line of each testcase contains a non-empty string $s$ , consisting only of Latin letters 'a'. The length of $s$ doesn't exceed $50$ .
The second line contains a non-empty string $t$ , consisting of lowercase Latin letters. The length of $t$ doesn't exceed $50$ .
输出格式
For each testcase, print the number of different strings $s$ that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.
输入输出样例
输入 #1
3 aaaa a aa abc a b
输出 #1
1 -1 2
In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
In the second example, you can replace the second letter 'a' with "abc". String $s$ becomes equal to "aabc". Then the second letter 'a' again. String $s$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.
In the third example, you can either leave string $s$ as is, performing zero moves, or replace the only 'a' with "b". String $s$ becomes equal to "b", so you can't perform more moves on it.
In the second example, you can replace the second letter 'a' with "abc". String $s$ becomes equal to "aabc". Then the second letter 'a' again. String $s$ becomes equal to "aabcbc". And so on, generating infinitely many different strings.
In the third example, you can either leave string $s$ as is, performing zero moves, or replace the only 'a' with "b". String $s$ becomes equal to "b", so you can't perform more moves on it.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted