Submission details
Task:Swapping letters
Sender:Wu xiaobo
Submission time:2020-09-20 01:29:47 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#2ACCEPTED0.01 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.23 sdetails
#5ACCEPTED0.13 sdetails
#6--details
#7--details
#8ACCEPTED0.12 sdetails
#9ACCEPTED0.04 sdetails
#10ACCEPTED0.04 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:24:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < x.size(); i++) {
                     ~~^~~~~~~~~~
input/code.cpp:48:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < x_ind.size(); j ++){
                         ~~^~~~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;


int main() {
    int n;
    cin >> n;
    char forbids[n][2];
    for (int i = 0; i < n; i++)
        cin >> forbids[i][0] >> forbids[i][1];
    string x, y;
    cin >> x >> y;
    if(x.length() != y.length()){
        cout << "NO";
        return 0;
    }
    map<char, vector<int> > x_letters;
    map<char, vector<int> > y_letters;

    for (int i = 0; i < x.size(); i++) {
        x_letters[x[i]].push_back(i);
        y_letters[y[i]].push_back(i);
    }

    for (int i = 0; i < n; i++) {
        char a, b;
        a = forbids[i][0];
        b = forbids[i][1];
        vector<int> x_ind;
        if (x_letters.find(a) != x_letters.end())
            x_ind.insert(x_ind.end(), x_letters[a].begin(), x_letters[a].end());
        if (x_letters.find(b) != x_letters.end())
            x_ind.insert(x_ind.end(), x_letters[b].begin(), x_letters[b].end());

        vector<int> y_ind;
        if (y_letters.find(a) != y_letters.end())
            y_ind.insert(y_ind.end(), y_letters[a].begin(), y_letters[a].end());
        if (y_letters.find(b) != y_letters.end())
            y_ind.insert(y_ind.end(), y_letters[b].begin(), y_letters[b].end());

        sort(x_ind.begin(), x_ind.end());
        sort(y_ind.begin(), y_ind.end());

        for (int j = 0; j < x_ind.size(); j ++){
            if(x[x_ind[j]] != y[y_ind[j]]){
                cout << "NO";
                return 0;
            }
        }
    }
    cout << "YES";
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
5
a b
b c
c d
d e
...

correct output
YES

user output
YES

Test 2

Verdict: ACCEPTED

input
2
a b
b c
acbbaca
cabbaac

correct output
YES

user output
YES

Test 3

Verdict: ACCEPTED

input
2
a b
b c
acbbaca
baccaab

correct output
NO

user output
NO

Test 4

Verdict: ACCEPTED

input
10
d c
e b
f y
h q
...

correct output
YES

user output
YES

Test 5

Verdict: ACCEPTED

input
10
a i
a l
d a
g h
...

correct output
NO

user output
NO

Test 6

Verdict:

input
325
a b
a e
a f
a g
...

correct output
YES

user output
(empty)

Test 7

Verdict:

input
325
a c
a e
a g
a h
...

correct output
NO

user output
(empty)

Test 8

Verdict: ACCEPTED

input
0
dlkinfmdyjaofxbccwhhbxzartqwdr...

correct output
YES

user output
YES

Test 9

Verdict: ACCEPTED

input
0
bxisdrdpgcsnnvhnfgimivzqpqjwqc...

correct output
NO

user output
NO

Test 10

Verdict: ACCEPTED

input
0
mrwduerojcguvxzmbomfsainvqehsl...

correct output
NO

user output
NO