Time Exceeded
Code
#include<bits/stdc++.h>
using namespace std;
/*
* @author abhishek
*
*/
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt;
cin>>tt;
while(tt--) {
int n;
cin>>n;
string s, p;
cin>>s>>p;
if(s==p) {
cout<<"YES"<<endl;
continue;
}
if(n==1) {
cout<<"NO"<<endl;
continue;
}
set<string>visited;
queue<string>q;
q.push(s);
visited.insert(s);
bool f= false;
while(!q.empty()) {
string curr= q.front();
q.pop();
for(int i=0;i<n-1;i++) {
for(string s1:{"01", "10"}) {
string next= curr;
next[i]= s1[0];
next[i+1]= s1[1];
if(!visited.count(next)) {
if(next==p) {
f= true;
break;
}
visited.insert(next);
q.push(next);
}
}
if(f) {
break;
}
}
if(f) {
break;
}
}
if(f) {
cout<<"YES"<<endl;
} else{
cout<<"NO"<<endl;
}
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1233 B. Make Binary Strings Equal
- Contest
- Happy New Year 2026
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2026-01-06 15:24:25
- Judged At
- 2026-01-06 15:24:25
- Judged By
- Score
- 5
- Total Time
- ≥601ms
- Peak Memory
- ≥33.297 MiB