#P10810. 【MX-S2-T1】 变

【MX-S2-T1】 变

Background

Original problem link: https://oier.team/problems/S2A

Problem Description

You are given a string ss consisting only of lowercase English letters.

In each operation, you may choose any character in ss and change it to any lowercase English letter.

You may perform at most kk operations in any order to minimize the length of the strict period of ss. Of course, you may also choose to perform no operations.

Output the smallest possible length of the strict period of ss after all operations.

A string tt is called a strict period of ss if and only if ss can be constructed by repeating tt some number of times.

For example, mai is a strict period of maimai, and dx is a strict period of dx. But ov is not a strict period of ovo

Input Format

The first line contains a non-negative integer kk.

The second line contains a string ss, consisting only of lowercase English letters.

Output Format

Output one integer on a single line, representing the answer.

1
test

4

3
test

1

3
apollo

3

Hint

[Sample Explanation #1]

It can be proven that with at most one operation, the strict period length is at least 44.

[Sample Explanation #2]

With 33 operations, you can change test into ssss, and the strict period length is 11.

[Constraints]

This problem uses bundled testdata.

  • Subtask 0 (17 pts): k=0k = 0, s6|s| \leq 6.
  • Subtask 1 (14 pts): k=1k = 1, s20|s| \leq 20.
  • Subtask 2 (16 pts): k=1k = 1, s500|s| \leq 500.
  • Subtask 3 (32 pts): k<s105k < |s| \leq 10^5.
  • Subtask 4 (21 pts): no special constraints.

For all testdata, it is guaranteed that 0k<s1060 \leq k < |s| \leq 10^6, and ss contains only lowercase English letters.

2024.7.28: A new Hack testdata set has been added.

Translated by ChatGPT 5