이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |