CodeForces 527B Error Correct System

Error Correct System

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status Practice CodeForces 527B

Description

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!

Input

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.

Output

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 ≤ ni ≠ 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.

Sample Input

Input

9pergamentpermanent

Output

14 6

Input

6wookiecookie

Output

1-1 -1

Input

4petregor

Output

21 2

Input

6doublebundle

Output

24 1

Hint

In the second test it is acceptable to print i = 2, j = 3.

 1 #include <stdio.h>
 2 #include <vector>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6
 7 char l1[200005],l2[200005];
 8 vector <int> x[35];
 9 vector <int> y[35];
10
11 int main()
12 {
13     int n,p,q;
14     int i,j,k;
15     while(scanf("%d",&n)!=EOF)
16     {
17         scanf("%s",l1+1);
18         scanf("%s",l2+1);
19         for(i=0;i<=30;i++)
20         {
21             x[i].clear();
22             y[i].clear();
23         }
24         p=-1,q=-1;
25         int flg=0,s=0;
26         for(i=1;i<=n;i++)
27         {
28             if(l1[i]!=l2[i])
29             {
30                 if(flg==0)
31                 {
32                     if(x[l2[i]-‘a‘+1].size()>0)
33                         p=x[l2[i]-‘a‘+1][0],q=i,flg=1;
34                     else if(y[l1[i]-‘a‘+1].size()>0)
35                         p=y[l1[i]-‘a‘+1][0],q=i,flg=1;
36                 }
37                 if(flg!=2)
38                 {
39                     for(j=0;j<x[l2[i]-‘a‘+1].size();j++)
40                     {
41                         k=x[l2[i]-‘a‘+1][j];
42                         if(l2[k]==l1[i])
43                         {
44                             p=k,q=i,flg=2;
45                             break;
46                         }
47                     }
48                 }
49                 s++;
50                 x[l1[i]-‘a‘+1].push_back(i);
51                 y[l2[i]-‘a‘+1].push_back(i);
52             }
53         }
54         printf("%d\n",s-flg);
55         printf("%d %d\n",p,q);
56     }
57     return 0;
58 }

时间: 2024-08-03 05:43:49

CodeForces 527B Error Correct System的相关文章

Error Correct System(模拟)

Error Correct System Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 527B Description Ford Prefect got a job as a web developer for a small company that makes towels. His current work ta

B. Error Correct System (CF Round #296 (Div. 2))

B. Error Correct System time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ford Prefect got a job as a web developer for a small company that makes towels. His current work task is to create

Fixed: The Windows Process Activation Service service terminated with the following error: The system cannot find the file specified

I'm not yet clear what I did, but I'm blogging it so it can be found if someone else has this issue. For whatever reason, last week both of my Vista 64-bit machines suddenly stopped being able to start IIS (Internet Information Server). The service j

android eclipse 报error loading /system/media/audio/ xxx 错的解决办法。

只针对 报错..error   loading /system/media/audio/ xxx.ogg 一步操作 解决烦恼..把 模拟器声音 关了..所有的错 都没了. 包括 关闭按键声音,触摸声音,铃声等.并且 铃声 设置 none. setting->> sound ->> 都关了. 和什么代码,程序都没有关系.多久都木有答案,一个巧合,错误就没了. PP:Couldn't open fd for content://settings/system/xx 同理,关 模拟器的铃

CodeForces 527B

Description 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 compari

mysql错误【一】[ERROR] Missing system table mysql.proxies_priv

环境:mysql一主一从架构,主库是mysql5.1,从库是mysql5.6:系统均为CentOS6.2 问题: 在主库上面执行的SQL语句 1.创建表 CREATE TABLE `app_versions` (  `date` date NOT NULL,  `app` char(16) NOT NULL,  `ver` char(16) NOT NULL,  `val` int(11) DEFAULT '0',  PRIMARY KEY (`date`,`app`,`ver`)) ENGIN

CodeForces Round#22 C System Administrator 构造割点图

题目描述: Description Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via thes

codeforces 527B:瞎搞

#include"cstdio" #include"queue" #include"cmath" #include"stack" #include"iostream" #include"algorithm" #include"cstring" #include"queue" #include"map" #include"

51NOD 1491 黄金系统 &amp;&amp; Codeforces 458 A. Golden System(斐波那契数列 + 找规律)

传送门 q = 5√+12在黄金系统下面a0a1...an等于 ∑ni=0ai?qn?i,其中ai 是 0 或者 1. 现在给出两个黄金系统下面的数字,请比较他们的大小. Input 单组测试数据. 第一行有一个字符串 a . 第二行有一个字符串 b . 他们都是非空串,可能有前导 0,并且只有 0 和 1组成,长度不超过 100000. Output 如果 a>b,输出 >: 如果 a= b,输出 =: 如果 a<b,输出 <: Input示例 00100 11 Output示例