CF527B.Error Correct System
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create a search engine for the website of the company. During the development process, he needs to write a subroutine for comparing strings S and T of equal length to be "similar". After a brief search on the Internet, he learned about the Hamming distance between two strings S and T of the same length, which is defined as the number of positions in which S and T have different characters. For example, the Hamming distance between words "permanent" and "pergament" is two, as these words differ in the fourth and sixth letters.
Moreover, as he was searching for information, he also noticed that modern search engines have powerful mechanisms to correct errors in the request to improve the quality of search. Ford doesn't know much about human beings, so he assumed that the most common mistake in a request is swapping two arbitrary letters of the string (not necessarily adjacent). Now he wants to write a function that determines which two letters should be swapped in string S, so that the Hamming distance between a new string S and string T would be as small as possible, or otherwise, determine that such a replacement cannot reduce the distance between the strings.
Help him do this!
福特·派法特(Ford Prefect)在一家生产毛巾的小公司担任网页开发工程师。他当前的工作任务是为该公司网站开发一个搜索引擎。在开发过程中,他需要编写一个子程序,用于判断两个等长字符串 S 和 T 是否“相似”。经过简短的网络搜索,他了解到:对于两个等长字符串 S 和 T,其**汉明距离(Hamming distance)**定义为 S 与 T 在相同位置上字符不同的位置个数。例如,“permanent”与“pergament”的汉明距离为 2,因为这两个单词在第 4 位和第 6 位上的字符不同。
此外,在查阅资料的过程中,他还注意到现代搜索引擎拥有强大的机制,可自动纠正用户查询中的错误,从而提升搜索质量。由于福特对人类了解甚少,他假设用户查询中最常见的错误是任意交换字符串中两个字符的位置(这两个字符不一定相邻)。现在,他希望编写一个函数,找出字符串 S 中应被交换的两个字符,使得交换后得到的新字符串 S′ 与字符串 T 的汉明距离尽可能小;若不存在任何交换操作能减小该汉明距离,则需判定这种情况。
请帮助他实现这一功能!
输入格式
The first line contains integer n (1 ≤ n ≤ 200 000) — the length of strings S and T.
The second line contains string S.
The third line contains string T.
Each of the lines only contains lowercase Latin letters.
第一行包含一个整数 n(1≤n≤200000)——字符串 S 和 T 的长度。
第二行包含字符串 S。
第三行包含字符串 T。
每行仅包含小写拉丁字母。
输出格式
In the first line, print number x — the minimum possible Hamming distance between strings S and T if you swap at most one pair of letters in S.
In the second line, either print the indexes i and j (1 ≤ i, j ≤ n, i ≠ j), if reaching the minimum possible distance is possible by swapping letters on positions i and j, or print "-1 -1", if it is not necessary to swap characters.
If there are multiple possible answers, print any of them.
第一行输出数字 x —— 在字符串 S 中至多交换一对字母后,字符串 S 与 T 之间可能达到的最小汉明距离。
第二行输出下标 i 和 j(1 ≤ i, j ≤ n,且 i = j),表示通过交换位置 i 和 j 上的字母即可达到上述最小距离;若无需交换字符即可达到该最小距离,则输出 -1 -1。
若存在多种可行答案,输出任意一种即可。
输入输出样例
输入#1
9 pergament permanent
输出#1
1 4 6
输入#2
6 wookie cookie
输出#2
1 -1 -1
输入#3
4 petr egor
输出#3
2 1 2
输入#4
6 double bundle
输出#4
2 4 1
说明/提示
In the second test it is acceptable to print i = 2, j = 3.
在第二个测试中,输出 i = 2、j = 3 是可以接受的。
输入解题思路,AI测评打分。不知道怎么写?