QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#833994#9726. AUSremain11#RE 0ms0kbC++201.1kb2024-12-27 09:41:402024-12-27 09:41:40

Judging History

你现在查看的是最新测评结果

  • [2024-12-27 09:41:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-12-27 09:41:40]
  • 提交

answer

#include <iostream>
#include <cassert>
using namespace std;

int fa[26];
int find(int x) {
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
int merge(int x, int y) {
    x = find(x);
    y = find(y);
    fa[x] = y;
}
void solve() {

    for (int i = 0; i < 26; ++i) fa[i] = i;

    string a, b, c;
    cin >> a >> b >> c;
    int cat[26], cnt = 0;
    for (int i = 0; i < 26; ++i) cat[i] = -1;
    if (a.length() != b.length()) {
        cout << "NO\n";
        return;
    }
    if (a.length() != c.length()) {
        cout << "YES\n";
        return;
    }
    int n = a.length();
    for (int i = 0; i < n; ++i) {
        int aa = find(a[i] - 'a');
        int bb = find(b[i] - 'a');
        if (aa != bb) merge(aa, bb); 
    }

    for (int i = 0; i < n; ++i) {
        int aa = find(a[i] - 'a');
        int cc = find(c[i] - 'a');
        if (aa != cc) {
            cout << "YES\n";
            return;
        }
    }
    cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T; cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
abab
cdcd
abce
abab
cdcd
abcd
abab
cdcd
abc
x
yz
def

output:


result: