CF612A.The Text Splitting

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.

For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".

Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).

给你一个长度为 nn 的字符串 ss 以及两个数 pp、qq。将字符串 ss 分割成若干段,每段的长度只能是 pp 或 qq。

例如,当 s="Hello"s = \texttt{"Hello"}、p=2p = 2、q=3q = 3 时,可以将其分割为两段:"Hel"\texttt{"Hel"} 和 "lo"\texttt{"lo"};也可以分割为 "He"\texttt{"He"} 和 "llo"\texttt{"llo"}。

注意:允许将字符串 ss 全部分割为长度均为 pp 的子串,也允许全部分割为长度均为 qq 的子串(参见第二个样例测试)。

输入格式

The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100).

The second line contains the string s consists of lowercase and uppercase latin letters and digits.

第一行包含三个正整数 nn、pp、qq(1 ≤ p, q ≤ n ≤ 1001 ≤ p, q ≤ n ≤ 100)。

第二行包含字符串 ss,由小写和大写拉丁字母以及数字组成。

输出格式

If it's impossible to split the string s to the strings of length p and q print the only number "-1".

Otherwise in the first line print integer k — the number of strings in partition of s.

Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right.

If there are several solutions print any of them.

如果无法将字符串 ss 分割为若干长度为 pp 或 qq 的子串,则仅输出数字 -1。

否则,第一行输出整数 kk —— 即字符串 ss 的分割中子串的个数。

接下来的 kk 行中,每行输出分割得到的一个子串。每个子串的长度必须为 pp 或 qq,且这些子串应按其在原字符串 ss 中从左到右出现的顺序输出。

若存在多种可行解,输出任意一种即可。

输入输出样例

  • 输入#1

    5 2 3
    Hello

    输出#1

    2
    He
    llo
  • 输入#2

    10 9 5
    Codeforces

    输出#2

    2
    Codef
    orces
  • 输入#3

    6 4 5
    Privet

    输出#3

    -1
  • 输入#4

    8 1 1
    abacabac

    输出#4

    8
    a
    b
    a
    c
    a
    b
    a
    c

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

首页