CF883H.Palindromic Cut

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kolya has a string s of length n consisting of lowercase and uppercase Latin letters and digits.

He wants to rearrange the symbols in s and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forward, such as madam or racecar.

Your task is to help Kolya and determine the minimum number of palindromes of equal lengths to cut s into, if it is allowed to rearrange letters in s before cuttings.

科里亚有一个长度为 nn 的字符串 ss,由小写和大写拉丁字母以及数字组成。

他希望重新排列 ss 中的字符,并将其分割成尽可能少的若干部分,使得每一部分都是回文串,且所有部分的长度均相等。回文串是指正读与反读都相同的字符串,例如 madam 或 racecar。

你的任务是帮助科里亚确定:在允许预先重新排列 ss 中字符的前提下,将 ss 分割成长度相等的回文串所需的最少部分数。

输入格式

The first line contains an integer n (1 ≤ n ≤ 4·105) — the length of string s.

The second line contains a string s of length n consisting of lowercase and uppercase Latin letters and digits.

第一行包含一个整数 nn(1≤n≤4⋅1051 \leq n \leq 4 \cdot 10^5)—— 字符串 ss 的长度。

第二行包含一个长度为 nn 的字符串 ss,由小写和大写拉丁字母以及数字组成。

输出格式

Print to the first line an integer k — minimum number of palindromes into which you can cut a given string.

Print to the second line k strings — the palindromes themselves. Separate them by a space. You are allowed to print palindromes in arbitrary order. All of them should have the same length.

第一行输出一个整数 kk —— 将给定字符串分割成回文串的最少数量。

第二行输出 kk 个字符串 —— 这些回文串本身,用空格分隔。允许以任意顺序输出这些回文串。所有回文串的长度必须相同。

输入输出样例

  • 输入#1

    6
    aabaac

    输出#1

    2
    aba aca
  • 输入#2

    8
    0rTrT022

    输出#2

    1
    02TrrT20
  • 输入#3

    2
    aA

    输出#3

    2
    a A

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

首页