Submission details
Task:Swapping letters
Sender:Wu xiaobo
Submission time:2020-09-19 15:57:33 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.07 sdetails
#20.08 sdetails
#30.07 sdetails
#40.21 sdetails
#50.21 sdetails
#60.22 sdetails
#70.22 sdetails
#8ACCEPTED0.19 sdetails
#9ACCEPTED0.19 sdetails
#10ACCEPTED0.19 sdetails

Code

# n = int(input())
#
# forbidden = {}
# for _ in range(n):
#     a, b = input().split()
#     if a not in forbidden:
#         forbidden[a] = {b}
#     else:
#         forbidden[a].add(b)
#
#     if b not in forbidden:
#         forbidden[b] = {a}
#     else:
#         forbidden[a].add(a)
#
# x = input()
# y = input()
#
# if len(x) != len(y):
#     print('NO')
# else:
#     # letters = set(x)
#     # for l in letters:
#     #     if x.count(l) != y.count(l):
#     #         print('NO')
#     #         break
#     # else:
#     for i in range(len(x)):
#         if x[i] == y[i]:
#             continue
#         ind = i + x[i+1:].index(y[i]) + 1
#         for j in range(i, ind):
#             if y[i] in forbidden and x[j] in forbidden[y[i]]:
#                 break
#         else:
#             x = x[:i] + x[ind] + x[i:ind] + x[ind + 1:]
#             continue
#         print('NO')
#         break
#     else:
#         print('YES')

n = int(input())
forbidden = []
for _ in range(n):
    a, b = input().split()
    forbidden.append([a, b])

x = input()
y = input()

x_letters = {}
y_letters = {}

for i, l in enumerate(x):
    if l in x_letters:
        x_letters.append(i)
    else:
        x_letters = [i]

for i, l in enumerate(y):
    if l in y_letters:
        y_letters.append(i)
    else:
        y_letters = [i]

if len(x) != len(y):
    print('NO')
else:
    for a, b in forbidden:
        ind_x = sorted(x_letters[a] + x_letters[b])
        ind_y = sorted(y_letters[a] + y_letters[b])

        if len(ind_x) != len(ind_y):
            print('NO')
            break
        for i in range(len(ind_x)):
            if x[ind_x[i]] != y[ind_y[i]]:
                break
        else:
            continue
        print('NO')
        break
    else:
        print('YES')

Test details

Test 1

Verdict:

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

correct output
YES

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 2

Verdict:

input
2
a b
b c
acbbaca
cabbaac

correct output
YES

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 3

Verdict:

input
2
a b
b c
acbbaca
baccaab

correct output
NO

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 4

Verdict:

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

correct output
YES

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 5

Verdict:

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

correct output
NO

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 6

Verdict:

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

correct output
YES

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

Test 7

Verdict:

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

correct output
NO

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 71, in <module>
    ind_x...

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