A - ST and TS Palindrome Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400400

問題文

英小文字からなる長さ NN の文字列 SS と正整数 KK が与えられます。

以下の条件を満たす長さ KK の文字列 SS' が存在するか判定してください。

  • S,SS, S' をこの順に結合して得られる文字列は回文である
  • S,SS', S をこの順に結合して得られる文字列は回文である

TT 個のテストケースが与えられるのでそれぞれについて判定してください。

制約

  • 1T1051 \leq T \leq 10^5
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1K10181 \leq K \leq 10^{18}
  • SS は英小文字からなる長さ NN の文字列
  • 入力される数値はすべて整数
  • 11 つの入力に含まれるテストケースについて、 NN の総和は 2×1052 \times 10^5 以下

入力

入力は以下の形式で標準入力から与えられます。

TT
case1\mathrm{case}_1
\vdots
caseT\mathrm{case}_T

各ケースは以下の形式で与えられます。

NN KK
SS

出力

TT 行出力せよ。ii 行目には ii 番目のテストケースについて、条件を満たす文字列 SS' が存在する場合は Yes を、存在しない場合は No を出力せよ。


入力例 1Copy

Copy
2
6 2
abbaab
5 3
abcbb

出力例 1Copy

Copy
Yes
No

11 番目のテストケースについて、例えば S=S' = {}ba とすると S,SS,S' をこの順に結合して得られる文字列 abbaabba は回文になっています。また、 S,SS',S をこの順に結合して得られる文字列 baabbaab も回文になっています。以上より S=S' = {}ba は条件を満たすので答えは Yes になります。

22 番目のテストケースについては、条件を満たす SS' が存在しないことが証明できます。


入力例 2Copy

Copy
3
12 400378271514996652
njvhhvjnnjvh
10 884633988115575508
rrhiyvrrur
36 71630165869626180
vsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh

出力例 2Copy

Copy
Yes
No
Yes

Score : 400400 points

Problem Statement

You are given a string SS of length NN consisting of lowercase English letters, and a positive integer KK.

Determine whether there is a string SS' of length KK that satisfies the following conditions.

  • The concatenation of SS and SS' in this order is a palindrome.
  • The concatenation of SS' and SS in this order is a palindrome.

You have TT test cases to solve.

Constraints

  • 1T1051 \leq T \leq 10^5
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1K10181 \leq K \leq 10^{18}
  • SS is a string of length NN consisting of lowercase English letters.
  • All numbers in the input are integers.
  • In each input file, the sum of NN over the test cases is at most 2×1052 \times 10^5.

Input

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
\vdots
caseT\mathrm{case}_T

Each case is in the following format:

NN KK
SS

Output

Print TT lines. The ii-th line should contain Yes if there is a string SS' that satisfies the conditions for the ii-th test case, and No otherwise.


Sample Input 1Copy

Copy
2
6 2
abbaab
5 3
abcbb

Sample Output 1Copy

Copy
Yes
No

For the first test case, if we let S=S' = {}ba, for instance, the concatenation of SS and SS' in this order will be abbaabba, which is a palindrome. Here, the concatenation of SS' and SS in this order is baabbaab, which is also a palindrome. Thus, S=S' = {}ba satisfies the condition, so the answer is Yes.

For the second test case, we can prove that no string satisfies the conditions.


Sample Input 2Copy

Copy
3
12 400378271514996652
njvhhvjnnjvh
10 884633988115575508
rrhiyvrrur
36 71630165869626180
vsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh

Sample Output 2Copy

Copy
Yes
No
Yes


2025-04-05 (Sat)
10:36:42 +00:00