#include <bits/stdc++.h>
#define eb emplace_back
#define printv(a, b) { \
for(auto pv : a) b << pv << " "; \
b << "\n"; \
}
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
string sa, sb;
cin >> n >> sa >> sb;
assert(n <= 18);
int a = bitset<20>(sa).to_ulong(), b = bitset<20>(sb).to_ulong();
vector<int> dis(1 << n, -1);
queue<int> q;
q.push(a);
dis[a] = 0;
while(!q.empty()){
int now = q.front();
q.pop();
for(int j = 0; j < n; j++){
int tmp = now;
for(int k = j; k < n; k++){
tmp ^= 1 << k;
if(dis[tmp] == -1){
dis[tmp] = dis[now] + 1;
q.push(tmp);
}
}
}
for(int j = 0; j < n; j++){
int tmp = now;
for(int k = j; k < n; k++){
tmp |= 1 << k;
if(dis[tmp] == -1){
dis[tmp] = dis[now] + 1;
q.push(tmp);
}
}
}
for(int j = 0; j < n; j++){
int tmp = now;
for(int k = j; k < n; k++){
if(1 << k & tmp) tmp ^= 1 << k;
if(dis[tmp] == -1){
dis[tmp] = dis[now] + 1;
q.push(tmp);
}
}
}
}
cout << dis[b] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
463 ms |
1772 KB |
Output is correct |
9 |
Correct |
444 ms |
1900 KB |
Output is correct |
10 |
Correct |
193 ms |
1004 KB |
Output is correct |
11 |
Correct |
200 ms |
1004 KB |
Output is correct |
12 |
Correct |
447 ms |
2028 KB |
Output is correct |
13 |
Correct |
190 ms |
1152 KB |
Output is correct |
14 |
Correct |
458 ms |
1772 KB |
Output is correct |
15 |
Correct |
199 ms |
1260 KB |
Output is correct |
16 |
Correct |
449 ms |
2080 KB |
Output is correct |
17 |
Correct |
189 ms |
1260 KB |
Output is correct |
18 |
Correct |
448 ms |
2028 KB |
Output is correct |
19 |
Correct |
195 ms |
1132 KB |
Output is correct |
20 |
Correct |
451 ms |
1928 KB |
Output is correct |
21 |
Correct |
193 ms |
1132 KB |
Output is correct |
22 |
Correct |
458 ms |
1900 KB |
Output is correct |
23 |
Correct |
199 ms |
1260 KB |
Output is correct |
24 |
Correct |
440 ms |
2028 KB |
Output is correct |
25 |
Correct |
194 ms |
1132 KB |
Output is correct |
26 |
Correct |
464 ms |
1900 KB |
Output is correct |
27 |
Correct |
189 ms |
1132 KB |
Output is correct |
28 |
Correct |
85 ms |
768 KB |
Output is correct |
29 |
Correct |
444 ms |
1900 KB |
Output is correct |
30 |
Correct |
194 ms |
1260 KB |
Output is correct |
31 |
Correct |
98 ms |
748 KB |
Output is correct |
32 |
Correct |
452 ms |
1900 KB |
Output is correct |
33 |
Correct |
194 ms |
1388 KB |
Output is correct |
34 |
Correct |
85 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
463 ms |
1772 KB |
Output is correct |
9 |
Correct |
444 ms |
1900 KB |
Output is correct |
10 |
Correct |
193 ms |
1004 KB |
Output is correct |
11 |
Correct |
200 ms |
1004 KB |
Output is correct |
12 |
Correct |
447 ms |
2028 KB |
Output is correct |
13 |
Correct |
190 ms |
1152 KB |
Output is correct |
14 |
Correct |
458 ms |
1772 KB |
Output is correct |
15 |
Correct |
199 ms |
1260 KB |
Output is correct |
16 |
Correct |
449 ms |
2080 KB |
Output is correct |
17 |
Correct |
189 ms |
1260 KB |
Output is correct |
18 |
Correct |
448 ms |
2028 KB |
Output is correct |
19 |
Correct |
195 ms |
1132 KB |
Output is correct |
20 |
Correct |
451 ms |
1928 KB |
Output is correct |
21 |
Correct |
193 ms |
1132 KB |
Output is correct |
22 |
Correct |
458 ms |
1900 KB |
Output is correct |
23 |
Correct |
199 ms |
1260 KB |
Output is correct |
24 |
Correct |
440 ms |
2028 KB |
Output is correct |
25 |
Correct |
194 ms |
1132 KB |
Output is correct |
26 |
Correct |
464 ms |
1900 KB |
Output is correct |
27 |
Correct |
189 ms |
1132 KB |
Output is correct |
28 |
Correct |
85 ms |
768 KB |
Output is correct |
29 |
Correct |
444 ms |
1900 KB |
Output is correct |
30 |
Correct |
194 ms |
1260 KB |
Output is correct |
31 |
Correct |
98 ms |
748 KB |
Output is correct |
32 |
Correct |
452 ms |
1900 KB |
Output is correct |
33 |
Correct |
194 ms |
1388 KB |
Output is correct |
34 |
Correct |
85 ms |
748 KB |
Output is correct |
35 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
36 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Runtime error |
9 ms |
4796 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
463 ms |
1772 KB |
Output is correct |
9 |
Correct |
444 ms |
1900 KB |
Output is correct |
10 |
Correct |
193 ms |
1004 KB |
Output is correct |
11 |
Correct |
200 ms |
1004 KB |
Output is correct |
12 |
Correct |
447 ms |
2028 KB |
Output is correct |
13 |
Correct |
190 ms |
1152 KB |
Output is correct |
14 |
Correct |
458 ms |
1772 KB |
Output is correct |
15 |
Correct |
199 ms |
1260 KB |
Output is correct |
16 |
Correct |
449 ms |
2080 KB |
Output is correct |
17 |
Correct |
189 ms |
1260 KB |
Output is correct |
18 |
Correct |
448 ms |
2028 KB |
Output is correct |
19 |
Correct |
195 ms |
1132 KB |
Output is correct |
20 |
Correct |
451 ms |
1928 KB |
Output is correct |
21 |
Correct |
193 ms |
1132 KB |
Output is correct |
22 |
Correct |
458 ms |
1900 KB |
Output is correct |
23 |
Correct |
199 ms |
1260 KB |
Output is correct |
24 |
Correct |
440 ms |
2028 KB |
Output is correct |
25 |
Correct |
194 ms |
1132 KB |
Output is correct |
26 |
Correct |
464 ms |
1900 KB |
Output is correct |
27 |
Correct |
189 ms |
1132 KB |
Output is correct |
28 |
Correct |
85 ms |
768 KB |
Output is correct |
29 |
Correct |
444 ms |
1900 KB |
Output is correct |
30 |
Correct |
194 ms |
1260 KB |
Output is correct |
31 |
Correct |
98 ms |
748 KB |
Output is correct |
32 |
Correct |
452 ms |
1900 KB |
Output is correct |
33 |
Correct |
194 ms |
1388 KB |
Output is correct |
34 |
Correct |
85 ms |
748 KB |
Output is correct |
35 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
36 |
Halted |
0 ms |
0 KB |
- |