이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int TAILLE_MAX=(1<<19);
int taille,init,obj,distCour,longueur;
char carac;
int dist[TAILLE_MAX];
deque<int> enCours;
int tout1(int deb,int fin) {
return (1<<(fin+1))-(1<<deb);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
for (int i=0;i<TAILLE_MAX;i++) {
dist[i]=-1;
}
cin>>taille;
for (int i=0;i<taille;i++) {
cin>>carac;
if (carac=='1') {
init+=(1<<i);
}
}
for (int i=0;i<taille;i++) {
cin>>carac;
if (carac=='1') {
obj+=(1<<i);
}
}
enCours.push_back(init);
int pos;
while (!enCours.empty()) {
longueur=enCours.size();
for (int i=0;i<longueur;i++) {
pos=enCours.front();
enCours.pop_front();
if (dist[pos]==-1) {
dist[pos]=distCour;
for (int deb=0;deb<taille;deb++) {
for (int fin=deb;fin<taille;fin++) {
enCours.push_back(pos^(tout1(deb,fin)));
enCours.push_back(pos|(tout1(deb,fin)));
enCours.push_back((pos|(tout1(deb,fin)))-tout1(deb,fin));
}
}
}
}
distCour++;
}
cout<<dist[obj]<<endl;
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... |