ST and TS Palindrome

AtCoder
IDarc155_a
Time2000ms
Memory256MB
Difficulty
You are given a string $S$ of length $N$ consisting of lowercase English letters, and a positive integer $K$. Determine whether there is a string $S'$ of length $K$ that satisfies the following conditions. * The concatenation of $S$ and $S'$ in this order is a palindrome. * The concatenation of $S'$ and $S$ in this order is a palindrome. You have $T$ test cases to solve. ## Constraints * $1 \leq T \leq 10^5$ * $1 \leq N \leq 2 \times 10^5$ * $1 \leq K \leq 10^{18}$ * $S$ is a string of length $N$ consisting of lowercase English letters. * All numbers in the input are integers. * In each input file, the sum of $N$ over the test cases is at most $2 \times 10^5$. ## Input The input is given from Standard Input in the following format: $T$ $\mathrm{case}_1$ $\vdots$ $\mathrm{case}_T$ Each case is in the following format: $N$ $K$ $S$ [samples]
Samples
Input #1
2
6 2
abbaab
5 3
abcbb
Output #1
Yes
No

For the first test case, if we let $S' = {}$`ba`, for instance, the concatenation of $S$ and $S'$ in this order will be `abbaabba`, which is a palindrome. Here, the concatenation of $S'$ and $S$ in this order is `baabbaab`, which is also a palindrome. Thus, $S' = {}$`ba` satisfies the condition, so the answer is `Yes`.
For the second test case, we can prove that no string satisfies the conditions.
Input #2
3
12 400378271514996652
njvhhvjnnjvh
10 884633988115575508
rrhiyvrrur
36 71630165869626180
vsxmxajrrduhhudrrjaxmxsvvsxmxajrrduh
Output #2
Yes
No
Yes
API Response (JSON)
{
  "problem": {
    "name": "ST and TS  Palindrome",
    "description": {
      "content": "You are given a string $S$ of length $N$ consisting of lowercase English letters, and a positive integer $K$. Determine whether there is a string $S'$ of length $K$ that satisfies the following condit",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc155_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$ of length $N$ consisting of lowercase English letters, and a positive integer $K$.\nDetermine whether there is a string $S'$ of length $K$ that satisfies the following condit...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments