#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621; //998244353
using namespace std;
const ll N = 1e6 + 10, LG = 20;
int n, dis[N];
queue<ll> q;
bool mark[N];
int main() {
fast_io;
string x, y;
cin >> n >> x >> y;
ll a = 0, b = 0;
for (int i = n - 1, j = 0; i >= 0; i--, j++)
a += (x[i] == '1') * (1 << j);
for (int i = n - 1, j = 0; i >= 0; i--, j++)
b += (y[i] == '1') * (1 << j);
q.push(a);
memset(dis, 63, sizeof dis);
dis[a] = 0;
mark[a] = true;
if (a == b) kill(0);
while (q.size()) {
int v = q.front();
q.pop();
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) {
int x = v;
for (int k = i; k <= j; k++)
if (x & (1 << k)) x ^= (1 << k);
if (!mark[x]) {
mark[x] = true;
q.push(x);
dis[x] = dis[v] + 1;
if (x == b) goto Hell;
}
}
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) {
int x = v;
for (int k = i; k <= j; k++)
if (!(x & (1 << k))) x ^= (1 << k);
if (!mark[x]) {
mark[x] = true;
q.push(x);
dis[x] = dis[v] + 1;
if (x == b) goto Hell;
}
}
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++) {
int x = v;
for (int k = i; k <= j; k++)
x ^= (1 << k);
if (!mark[x]) {
mark[x] = true;
q.push(x);
dis[x] = dis[v] + 1;
if (x == b) goto Hell;
}
}
}
Hell:;
cout << dis[b] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
5024 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Execution timed out |
1034 ms |
6260 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
5024 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Execution timed out |
1034 ms |
6260 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Correct |
1 ms |
4956 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
7 ms |
9128 KB |
Output is correct |
8 |
Execution timed out |
1031 ms |
9136 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Correct |
1 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4952 KB |
Output is correct |
4 |
Correct |
1 ms |
5024 KB |
Output is correct |
5 |
Correct |
1 ms |
4956 KB |
Output is correct |
6 |
Correct |
1 ms |
4956 KB |
Output is correct |
7 |
Correct |
1 ms |
4952 KB |
Output is correct |
8 |
Execution timed out |
1034 ms |
6260 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |