Submission details
Task:Swapping letters
Sender:kkivimaki
Submission time:2020-09-19 16:01:23 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#4--details
#50.90 sdetails
#6--details
#70.06 sdetails
#8--details
#9--details
#10--details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:35:14: warning: array subscript has type 'char' [-Wchar-subscripts]
         l0[c0].push_back(c1);
              ^
input/code.cpp:36:14: warning: array subscript has type 'char' [-Wchar-subscripts]
         l0[c1].push_back(c0);
              ^
input/code.cpp:54:29: warning: array subscript has type 'char' [-Wchar-subscripts]
         int j = find(y, at[c], c);
                             ^
input/code.cpp:55:13: warning: array subscript has type 'char' [-Wchar-subscripts]
         at[c] = j + 1;
             ^
input/code.cpp:57:26: warning: array subscript has type 'char' [-Wchar-subscripts]
         for (int r : l0[c]) {
                          ^
input/code.cpp:60:26: warning: array subscript has type 'char' [-Wchar-subscripts]
             int a = pvy[c][r];
                          ^
input/code.cpp:66:18: warning: array subscript has type 'char' [-Wchar-subscripts]
             pvy[c][r] = a + 1;
                  ^
input/...

Code

#include <vector>
#include <iostream>
#include <string>

std::vector<int> l0[1000];
int at[123];
int prx[123];
int pry[123][123];
int pvy[123][123];

int find(const char* y, int a, char c) {
    int i = a;
    while(y[i] != c) i++;
    return i;
}

int main() {
    for(int i = 0; i < 123; i++)  {
        for(int j = 0; j < 123; j++)  {
            pvy[i][j] = 0;
            pry[i][j] = 0;
        }
    }

    int n;
    std::cin >> n;

    while (n > 0) {
        n -= 1;
        char c0;
        char c1;
        std::cin >> c0;
        std::cin >> c1;

        l0[c0].push_back(c1);
        l0[c1].push_back(c0);
    }

    std::string x0;
    std::string y0;

    std::cin >> x0;
    std::cin >> y0;

    int N = x0.size();

    const char* x = x0.c_str();
    const char* y = y0.c_str();

    int i = 0;
    for(int i = 0; i < N; i++) {
        std::cout << i << " " << N << std::endl;
        char c = x[i];
        int j = find(y, at[c], c);
        at[c] = j + 1;

        for (int r : l0[c]) {
            int cx = prx[r];

            int a = pvy[c][r];
            int n = 0;
            while(y[a] != c) {
                if (y[a] == r) n++;
                a += 1;
            }
            pvy[c][r] = a + 1;
            pry[c][r] += n;
            int cy = pry[c][r];

            if (cx != cy) {
                std::cout << "NO" << std::endl;
                return 0;
            }
        }
        prx[c] += 1;
    }
    std::cout << "YES" << std::endl;
    return 0;
}

Test details

Test 1

Verdict:

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

correct output
YES

user output
0 8
1 8
2 8
3 8
4 8
...

Test 2

Verdict:

input
2
a b
b c
acbbaca
cabbaac

correct output
YES

user output
0 7
1 7
2 7
3 7
4 7
...

Test 3

Verdict:

input
2
a b
b c
acbbaca
baccaab

correct output
NO

user output
0 7
NO

Test 4

Verdict:

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

correct output
YES

user output
(empty)

Test 5

Verdict:

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

correct output
NO

user output
0 1000000
1 1000000
2 1000000
3 1000000
4 1000000
...
Truncated

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
0 1000000
1 1000000
2 1000000
3 1000000
4 1000000
...
Truncated

Test 8

Verdict:

input
0
dlkinfmdyjaofxbccwhhbxzartqwdr...

correct output
YES

user output
(empty)

Test 9

Verdict:

input
0
bxisdrdpgcsnnvhnfgimivzqpqjwqc...

correct output
NO

user output
(empty)

Test 10

Verdict:

input
0
mrwduerojcguvxzmbomfsainvqehsl...

correct output
NO

user output
(empty)