QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#1444. 回文

Statistiques

Zenyk 买了一个长度为 $n$ 的字符串,其中只包含字符 $0$ 和 $1$。他想把它送给 Marichka,但他知道 Marichka 只喜欢回文串(即正读和反读都一样的字符串),并且只有收到这样的礼物她才会满意。

在每一个小时内,Zenyk 可以将字符串中的任意一个字符移动到字符串的末尾。请问 Zenyk 最少需要多少小时才能为 Marichka 准备好一份礼物?

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 300$)。第二行包含一个长度为 $n$ 的字符串,仅由 $0$ 和 $1$ 组成。

输出格式

如果 Zenyk 成功准备好了礼物,则输出一个整数——即所需的最少小时数。

如果他无法做到,则输出 “-1”(不含引号)。

样例

样例输入 1

7
1101001

样例输出 1

1

样例输入 2

4
1001

样例输出 2

0

样例输入 3

12
110100010011

样例输出 3

3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.