CF432D.Prefixes and Suffixes

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a string s = _s_1_s_2...s|s|, where |s| is the length of string s, and s__i its i-th character.

Let's introduce several definitions:

  • A substring s[i..j] (1 ≤ i ≤ j ≤ |s|) of string s is string s__i__s__i + 1...s__j.
  • The prefix of string s of length l (1 ≤ l ≤ |s|) is string s[1..l].
  • The suffix of string s of length l (1 ≤ l ≤ |s|) is string s[|s| - l + 1..|s|].

Your task is, for any prefix of string s which matches a suffix of string s, print the number of times it occurs in string s as a substring.

你有一个字符串 s=s1s2…s∣s∣s = s_1s_2\ldots s_{|s|},其中 ∣s∣|s| 表示字符串 ss 的长度,sis_i 表示 ss 的第 ii 个字符。

我们引入如下定义:

  • 字符串 ss 的子串 s[i..j]s[i..j](其中 1≤i≤j≤∣s∣1 \le i \le j \le |s|)定义为字符串 sisi+1…sjs_is_{i+1}\ldots s_j。
  • 字符串 ss 长度为 ll(其中 1≤l≤∣s∣1 \le l \le |s|)的前缀定义为字符串 s[1..l]s[1..l]。
  • 字符串 ss 长度为 ll(其中 1≤l≤∣s∣1 \le l \le |s|)的后缀定义为字符串 s[∣s∣−l+1..∣s∣]s[|s| - l + 1..|s|]。

你的任务是:对字符串 ss 的每一个既是前缀又是后缀的子串,输出它在 ss 中作为子串出现的总次数。

输入格式

The single line contains a sequence of characters _s_1_s_2...s|s| (1 ≤ |s| ≤ 105) — string s. The string only consists of uppercase English letters.

单行包含一个字符序列 s1s2…s∣s∣s_1s_2\ldots s_{|s|}(1 ≤ ∣s∣ ≤ 1051 \le |s| \le 10^5)——字符串 ss。该字符串仅由大写英文字母组成。

输出格式

In the first line, print integer k (0 ≤ k ≤ |s|) — the number of prefixes that match a suffix of string s. Next print k lines, in each line print two integers l__i c__i. Numbers l__i c__i mean that the prefix of the length l__i matches the suffix of length l__i and occurs in string s as a substring c__i times. Print pairs l__i c__i in the order of increasing l__i.

第一行输出一个整数 kk(0≤k≤∣s∣0 \leq k \leq |s|),表示字符串 ss 中与某个后缀相匹配的前缀个数。接下来输出 kk 行,每行输出两个整数 lil_i 和 cic_i。其中 lil_i 和 cic_i 表示长度为 lil_i 的前缀与长度为 lil_i 的后缀相匹配,并且该前缀作为子串在字符串 ss 中共出现 cic_i 次。请按 lil_i 递增的顺序输出所有数对 (li,ci)(l_i, c_i)。

输入输出样例

  • 输入#1

    ABACABA

    输出#1

    3
    1 4
    3 2
    7 1
  • 输入#2

    AAA

    输出#2

    3
    1 3
    2 2
    3 1

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

首页