/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 544.0 KiB
#2 Accepted 2ms 536.0 KiB
#3 Accepted 4ms 532.0 KiB
#4 Accepted 3ms 764.0 KiB
#5 Accepted 4ms 536.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define eb emplace_back
#define bug(x) cerr << #x << " = " << x << endl

#define rem(v,x) (v).erase(remove((v).begin(), (v).end(), (x)), (v).end())
#define leftrotate(v,k) rotate((v).begin(), (v).begin() + ((k) % (v).size()), (v).end())
#define rightrotate(v,k) rotate((v).begin(), (v).end() - ((k) % (v).size()), (v).end())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define lz(x) __builtin_clz(x)
#define lzll(x) __builtin_clzll(x)
#define tz(x) __builtin_ctz(x)
#define tzll(x) __builtin_ctzll(x)

void fast() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
template <typename T>
void print(const vector<T>& vec) { for (const auto& val : vec) cout << val << " "; cout << endl; }

void solve() {
    int n; cin >> n;
    string a, b;
    cin >> a >> b;

    if(n == 1 && a != b){
        cout << "NO" << endl;
        return;
    }

    if(a == b){
        cout << "YES" << endl;
        return;
    }

    vector<int> fa(2), fb(2);

    for(int i = 0; i < n; i++){
        if(a[i] == '1') fa[1]++;
        if(a[i] == '0') fa[0]++;
        if(b[i] == '1') fb[1]++;
        if(b[i] == '0') fb[0]++;
    }    

    if(fa[0] == fb[0]){
        cout << "YES" << endl;
        return;
    } 

    if(fb[1] == 0 || fb[1] == n){
        cout << "NO" << endl;
        return;
    }

    cout << "YES" << endl;
}

int main() {
    fast();
    int t = 1;
    cin >> t;
    while (t--) solve();
}
    

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:04:58
Judged At
2026-01-06 15:04:58
Judged By
Score
100
Total Time
4ms
Peak Memory
764.0 KiB