This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |