CF884F.Anti-Palindromize

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a__i ≠ a__m - i + 1.

Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b__i, and the beauty of t as the sum of b__i among all indices i such that s__i = t__i.

Help Ivan to determine maximum possible beauty of t he can get.

长度为 mm 的字符串 aa 被称为反回文串(antipalindromic),当且仅当 mm 为偶数,且对每个 ii(1≤i≤m1 \le i \le m),都有 ai≠am−i+1a_i \ne a_{m-i+1}。

Ivan 有一个由 nn 个小写拉丁字母组成的字符串 ss;其中 nn 是偶数。他希望构造出某个字符串 tt,使得 tt 是 ss 的一个反回文排列(即 tt 是 ss 的一个排列,且 tt 本身是反回文串)。此外,Ivan 将下标 ii 的“美观度”记为 bib_i,而字符串 tt 的美观度定义为:对所有满足 si=tis_i = t_i 的下标 ii,对应的 bib_i 值之和。

请帮助 Ivan 确定他所能得到的 tt 的最大可能美观度。

输入格式

The first line contains one integer n (2 ≤ n ≤ 100, n is even) — the number of characters in s.

The second line contains the string s itself. It consists of only lowercase Latin letters, and it is guaranteed that its letters can be reordered to form an antipalindromic string.

The third line contains n integer numbers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ 100), where b__i is the beauty of index i.

第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100,且 nn 为偶数)—— 表示字符串 ss 的字符个数。

第二行包含字符串 ss 本身。它仅由小写拉丁字母组成,且保证其字符可以重新排列成一个反回文串(antipalindromic string)。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1001 \leq b_i \leq 100),其中 bib_i 表示位置 ii 的美观度。

输出格式

Print one number — the maximum possible beauty of t.

输出一个数字——字符串 tt 的最大可能美观度。

输入输出样例

  • 输入#1

    8
    abacabac
    1 1 1 1 1 1 1 1

    输出#1

    8
  • 输入#2

    8
    abaccaba
    1 2 3 4 5 6 7 8

    输出#2

    26
  • 输入#3

    8
    abacabca
    1 2 3 4 4 3 2 1

    输出#3

    17

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

首页