CF1674C.Infinite Replacement

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string ss, consisting only of Latin letters 'a', and a string tt, consisting of lowercase Latin letters.

In one move, you can replace any letter 'a' in the string ss with a string tt. Note that after the replacement string ss 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.

给你一个仅由拉丁字母 'a' 组成的字符串 ss,以及一个由小写拉丁字母组成的字符串 tt。

在一次操作中,你可以将字符串 ss 中的任意一个字母 'a' 替换为字符串 tt。注意:替换后,字符串 ss 可能包含除 'a' 以外的其他字母。

你可以执行任意次数(包括零次)这样的操作。你最多能得到多少个不同的字符串?请输出该数目;若数目无限大,则报告这一点。

如果两个字符串长度不同,或在某个下标处字符不同,则认为它们是不同的字符串。

输入格式

The first line contains a single integer qq (1≤q≤1041 \le q \le 10^4) — the number of testcases.

The first line of each testcase contains a non-empty string ss, consisting only of Latin letters 'a'. The length of ss doesn't exceed 5050.

The second line contains a non-empty string tt, consisting of lowercase Latin letters. The length of tt doesn't exceed 5050.

第一行包含一个整数 qq(1≤q≤1041 \le q \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含一个非空字符串 ss,仅由拉丁字母 'a' 组成。字符串 ss 的长度不超过 5050。

每个测试用例的第二行包含一个非空字符串 tt,由小写拉丁字母组成。字符串 tt 的长度不超过 5050。

输出格式

For each testcase, print the number of different strings ss that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

对于每个测试用例,输出经过任意次数(包括零次)操作后所能得到的不同字符串 ss 的数量。如果该数量为无穷大,则输出 -1;否则,输出该数量。

输入输出样例

  • 输入#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 ss becomes equal to "aabc". Then the second letter 'a' again. String ss becomes equal to "aabcbc". And so on, generating infinitely many different strings.

In the third example, you can either leave string ss as is, performing zero moves, or replace the only 'a' with "b". String ss becomes equal to "b", so you can't perform more moves on it.

在第一个例子中,你可以将任意字母 'a' 替换为字符串 "a",但这不会改变原字符串。因此,无论进行多少次操作,你都无法得到与初始字符串不同的字符串。

在第二个例子中,你可以将第二个字母 'a' 替换为 "abc",此时字符串 ss 变为 "aabc";接着再次将第二个字母 'a' 替换为 "abc",字符串 ss 变为 "aabcbc";依此类推,从而生成无限多个不同的字符串。

在第三个例子中,你可以选择保持字符串 ss 不变(即执行零次操作),或者将唯一的 'a' 替换为 "b",此时字符串 ss 变为 "b",此后便无法再执行任何操作。

输入解题思路,AI测评打分。不知道怎么写?

首页