| Task: | Swapping letters |
| Sender: | Wu xiaobo |
| Submission time: | 2020-09-19 15:42:22 +0300 |
| Language: | Python3 (CPython3) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.02 s | details |
| #2 | ACCEPTED | 0.02 s | details |
| #3 | ACCEPTED | 0.02 s | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | ACCEPTED | 0.53 s | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | TIME LIMIT EXCEEDED | -- | details |
| #8 | ACCEPTED | 0.03 s | details |
| #9 | ACCEPTED | 0.03 s | details |
| #10 | ACCEPTED | 0.03 s | details |
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()
if len(x) != len(y):
print('NO')
else:
for a, b in forbidden:
i = j = 0
while i < len(x) and j < len(x):
while i < len(x) and x[i] != a and x[i] != b:
i += 1
while j < len(x) and y[j] != a and y[j] != b:
j += 1
if i < len(x) and j < len(x) and x[i] != y[j]:
break
i += 1
j += 1
# af, bf = False, False
# for i in range(len(x)):
# if x[i] == a:
else:
continue
print('NO')
break
else:
print('YES')
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: TIME LIMIT EXCEEDED
| input |
|---|
| 10 d c e b f y h q ... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 10 a i a l d a g h ... |
| correct output |
|---|
| NO |
| user output |
|---|
| NO |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 325 a b a e a f a g ... |
| correct output |
|---|
| YES |
| user output |
|---|
| (empty) |
Test 7
Verdict: TIME LIMIT EXCEEDED
| 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 |
