Submission details
Task:Swapping letters
Sender:kkivimaki
Submission time:2020-09-19 14:14:40 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#10.02 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.02 sdetails
#40.55 sdetails
#5ACCEPTED0.55 sdetails
#6--details
#7--details
#8--details
#9ACCEPTED0.54 sdetails
#10ACCEPTED0.54 sdetails

Code



l0 = {}
f = {}

for c in 'abcdefghijklmnopqrstuvwxyz':
    l0[c] = []
    f[c] = 1

def find(y, c, m):
    i = 0
    while True:
        if y[i] is c:
            m -= 1
            if m <= 0:
                return i
        i += 1

def main():
    n = int(input())
    
    while n > 0:
        n -= 1
        cs = input()
        c0 = cs[0]
        c1 = cs[2]
        l0[c0] += c1
        l0[c1] += c0
    
    
    
    x = input()
    y = input()

    if sorted(x) != sorted(y):
        print("NO")
        return

    i = 0
    while i < len(x):
        c = x[i]

        j = find(y, c, f[c])

        for r in l0[c]:
            if x[0:i].count(r) != x[0:j].count(r):
                #print(r)
                #print(i, j)
                print("NO")
                return
        f[c] += 1
        i += 1

    print("YES")

main()

Test details

Test 1

Verdict:

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

correct output
YES

user output
NO

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:

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

correct output
YES

user output
NO

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:

input
0
dlkinfmdyjaofxbccwhhbxzartqwdr...

correct output
YES

user output
(empty)

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