#include <bits/stdc++.h>
using namespace std;
string a,b;
int n;
map<string,int> dis;
map<string,string > st;
int main()
{
cin >> n >> a >> b;
queue<string> q;
q.push(a);
dis[a]=0;
while(q.size())
{
string s=q.front(); q.pop();
if(s==b) break;
for(int i=0;i<n;i++)
{
string sd=s;
for(int j=i;j<n;j++)
{
sd[j]='0';
if(dis.count(sd)) continue;
dis[sd]=dis[s]+1;
st[sd]=s;
q.push(sd);
}
}
for(int i=0;i<n;i++)
{
string sd=s;
for(int j=i;j<n;j++)
{
sd[j]='1';
if(dis.count(sd)) continue;
dis[sd]=dis[s]+1;
st[sd]=s;
q.push(sd);
}
}
for(int i=0;i<n;i++)
{
string sd=s;
for(int j=i;j<n;j++)
{
sd[j]=(1-(s[j]-'0'))+'0';
if(dis.count(sd)) continue;
dis[sd]=dis[s]+1;
st[sd]=s;
q.push(sd);
}
}
}
cout << dis[b] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Execution timed out |
1073 ms |
19676 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Execution timed out |
1073 ms |
19676 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
120 ms |
7268 KB |
Output is correct |
8 |
Execution timed out |
1057 ms |
7268 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Execution timed out |
1073 ms |
19676 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |