CF906E.Reverses

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Hurricane came to Berland and to suburbs Stringsvill. You are going to it to check if it's all right with you favorite string. Hurrinace broke it a bit by reversing some of its non-intersecting substrings. You have a photo of this string before hurricane and you want to restore it to original state using reversing minimum possible number of its substrings and find out which substrings you should reverse.

You are given a string s — original state of your string and string t — state of the string after hurricane. You should select k non-intersecting substrings of t in such a way that after reverse of these substrings string will be equal s and k is minimum possible.

飓风袭击了贝尔兰以及其郊区——字符串镇(Stringsvill)。你正前往那里,检查你最喜爱的字符串是否安然无恙。飓风对它造成了一定破坏:通过翻转该字符串中若干个互不相交的子串,改变了它的形态。你手中有一张该字符串在飓风前的照片,现在希望仅通过翻转尽可能少的子串,将当前字符串恢复为原始状态,并确定需要翻转哪些子串。

给定字符串 ss —— 字符串的原始状态,以及字符串 tt —— 飓风后的状态。你需要从 tt 中选出 kk 个互不相交的子串,使得将这些子串各自翻转后,tt 恰好变为 ss,且 kk 为可能的最小值。

输入格式

First line of input contains string s and second line contains string t. Both strings have same length and consist of lowercase English letters. 1 ≤ |s| = |t| ≤ 5·105

输入的第一行包含字符串 ss,第二行包含字符串 tt。两个字符串长度相同,且均由小写英文字母组成。1 ≤ ∣s∣ = ∣t∣ ≤ 5⋅1051 \le |s| = |t| \le 5\cdot10^5

输出格式

In first line print k — minimum number of substrings you should reverse. Next output k lines. Each line should contain two integers l__i, r__i meaning that you should reverse substring from symbol number l__i to symbol r__i (strings are 1-indexed). These substrings shouldn't intersect. If there are multiple answers print any. If it's impossible to restore string output -1.

第一行输出 k —— 你需要翻转的子串的最少数量。接下来输出 k 行,每行包含两个整数 l__i、r__i,表示你需要翻转从第 l__i 个字符到第 r__i 个字符的子串(字符串下标从 1 开始)。这些子串之间不能相交。若存在多个答案,输出任意一个即可。若无法恢复该字符串,则输出 -1。

输入输出样例

  • 输入#1

    abcxxxdef
    cbaxxxfed

    输出#1

    2
    7 9
    1 3

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

首页