#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef array<int, 2> pii;
#define pb push_back
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
const int N = 18;
int n, d[1 << N];
bool vis[1 << N];
string a, b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
int ia = 0, ib = 0;
for (int i = 0; i < n; ++i) {
if (a[i] == '1')
ia += (1 << i);
if (b[i] == '1')
ib += (1 << i);
}
queue<int> q;
q.push(ia);
vis[ia] = 1;
while (!q.empty()) {
int v = q.front();
q.pop();
if (v == ib) {
cout << d[v];
return 0;
}
for (int l = 0; l < n; ++l) {
for (int r = l; r < n; ++r) {
int u = v;
for (int i = l; i <= r; ++i)
u |= (1 << i);
if (!vis[u]) {
q.push(u);
vis[u] = 1;
d[u] = d[v] + 1;
}
u = v;
for (int i = l; i <= r; ++i)
if (u & (1 << i))
u ^= (1 << i);
if (!vis[u]) {
q.push(u);
vis[u] = 1;
d[u] = d[v] + 1;
}
u = v;
for (int i = l; i <= r; ++i)
u ^= (1 << i);
if (!vis[u]) {
q.push(u);
vis[u] = 1;
d[u] = d[v] + 1;
}
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
951 ms |
2372 KB |
Output is correct |
9 |
Correct |
948 ms |
2136 KB |
Output is correct |
10 |
Correct |
435 ms |
1296 KB |
Output is correct |
11 |
Correct |
408 ms |
1304 KB |
Output is correct |
12 |
Correct |
57 ms |
2384 KB |
Output is correct |
13 |
Correct |
331 ms |
1360 KB |
Output is correct |
14 |
Correct |
116 ms |
2120 KB |
Output is correct |
15 |
Correct |
301 ms |
1568 KB |
Output is correct |
16 |
Correct |
415 ms |
2244 KB |
Output is correct |
17 |
Correct |
184 ms |
1372 KB |
Output is correct |
18 |
Correct |
188 ms |
2128 KB |
Output is correct |
19 |
Correct |
57 ms |
1116 KB |
Output is correct |
20 |
Correct |
722 ms |
2248 KB |
Output is correct |
21 |
Correct |
19 ms |
1116 KB |
Output is correct |
22 |
Correct |
225 ms |
2240 KB |
Output is correct |
23 |
Correct |
339 ms |
1112 KB |
Output is correct |
24 |
Correct |
19 ms |
1884 KB |
Output is correct |
25 |
Correct |
5 ms |
1116 KB |
Output is correct |
26 |
Correct |
616 ms |
2264 KB |
Output is correct |
27 |
Correct |
256 ms |
1220 KB |
Output is correct |
28 |
Correct |
63 ms |
896 KB |
Output is correct |
29 |
Correct |
753 ms |
2124 KB |
Output is correct |
30 |
Correct |
221 ms |
1368 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
85 ms |
2032 KB |
Output is correct |
33 |
Correct |
237 ms |
1116 KB |
Output is correct |
34 |
Correct |
92 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
951 ms |
2372 KB |
Output is correct |
9 |
Correct |
948 ms |
2136 KB |
Output is correct |
10 |
Correct |
435 ms |
1296 KB |
Output is correct |
11 |
Correct |
408 ms |
1304 KB |
Output is correct |
12 |
Correct |
57 ms |
2384 KB |
Output is correct |
13 |
Correct |
331 ms |
1360 KB |
Output is correct |
14 |
Correct |
116 ms |
2120 KB |
Output is correct |
15 |
Correct |
301 ms |
1568 KB |
Output is correct |
16 |
Correct |
415 ms |
2244 KB |
Output is correct |
17 |
Correct |
184 ms |
1372 KB |
Output is correct |
18 |
Correct |
188 ms |
2128 KB |
Output is correct |
19 |
Correct |
57 ms |
1116 KB |
Output is correct |
20 |
Correct |
722 ms |
2248 KB |
Output is correct |
21 |
Correct |
19 ms |
1116 KB |
Output is correct |
22 |
Correct |
225 ms |
2240 KB |
Output is correct |
23 |
Correct |
339 ms |
1112 KB |
Output is correct |
24 |
Correct |
19 ms |
1884 KB |
Output is correct |
25 |
Correct |
5 ms |
1116 KB |
Output is correct |
26 |
Correct |
616 ms |
2264 KB |
Output is correct |
27 |
Correct |
256 ms |
1220 KB |
Output is correct |
28 |
Correct |
63 ms |
896 KB |
Output is correct |
29 |
Correct |
753 ms |
2124 KB |
Output is correct |
30 |
Correct |
221 ms |
1368 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
85 ms |
2032 KB |
Output is correct |
33 |
Correct |
237 ms |
1116 KB |
Output is correct |
34 |
Correct |
92 ms |
1112 KB |
Output is correct |
35 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
4496 KB |
Output is correct |
8 |
Runtime error |
7 ms |
6828 KB |
Execution killed with signal 11 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
951 ms |
2372 KB |
Output is correct |
9 |
Correct |
948 ms |
2136 KB |
Output is correct |
10 |
Correct |
435 ms |
1296 KB |
Output is correct |
11 |
Correct |
408 ms |
1304 KB |
Output is correct |
12 |
Correct |
57 ms |
2384 KB |
Output is correct |
13 |
Correct |
331 ms |
1360 KB |
Output is correct |
14 |
Correct |
116 ms |
2120 KB |
Output is correct |
15 |
Correct |
301 ms |
1568 KB |
Output is correct |
16 |
Correct |
415 ms |
2244 KB |
Output is correct |
17 |
Correct |
184 ms |
1372 KB |
Output is correct |
18 |
Correct |
188 ms |
2128 KB |
Output is correct |
19 |
Correct |
57 ms |
1116 KB |
Output is correct |
20 |
Correct |
722 ms |
2248 KB |
Output is correct |
21 |
Correct |
19 ms |
1116 KB |
Output is correct |
22 |
Correct |
225 ms |
2240 KB |
Output is correct |
23 |
Correct |
339 ms |
1112 KB |
Output is correct |
24 |
Correct |
19 ms |
1884 KB |
Output is correct |
25 |
Correct |
5 ms |
1116 KB |
Output is correct |
26 |
Correct |
616 ms |
2264 KB |
Output is correct |
27 |
Correct |
256 ms |
1220 KB |
Output is correct |
28 |
Correct |
63 ms |
896 KB |
Output is correct |
29 |
Correct |
753 ms |
2124 KB |
Output is correct |
30 |
Correct |
221 ms |
1368 KB |
Output is correct |
31 |
Correct |
2 ms |
856 KB |
Output is correct |
32 |
Correct |
85 ms |
2032 KB |
Output is correct |
33 |
Correct |
237 ms |
1116 KB |
Output is correct |
34 |
Correct |
92 ms |
1112 KB |
Output is correct |
35 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
36 |
Halted |
0 ms |
0 KB |
- |