Task: | Swapping letters |
Sender: | MrAurela |
Submission time: | 2020-09-19 14:36:04 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.04 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | RUNTIME ERROR | 0.37 s | details |
#5 | RUNTIME ERROR | 0.36 s | details |
#6 | ACCEPTED | 0.04 s | details |
#7 | RUNTIME ERROR | 0.38 s | details |
#8 | RUNTIME ERROR | 0.38 s | details |
#9 | RUNTIME ERROR | 0.38 s | details |
#10 | RUNTIME ERROR | 0.35 s | details |
Code
import queue n = int(input()) forbidden = set() for i in range(n): tup = input().split() forbidden.add(tup[0]+tup[1]) forbidden.add(tup[1]+tup[0]) x = input() y = input() left = queue.Queue() left.put(x) visited = set() while not left.empty(): current = left.get() #print(current) if current == y: break if current not in visited: for i in range(len(current)-1): if current[i]+current[i+1] not in forbidden: nex = current[:i]+current[i+1]+current[i]+current[i+2:] left.put(nex) visited.add(current) if current == y: print("YES") else: print("NO")
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: RUNTIME ERROR
input |
---|
10 d c e b f y h q ... |
correct output |
---|
YES |
user output |
---|
(empty) |
Test 5
Verdict: RUNTIME ERROR
input |
---|
10 a i a l d a g h ... |
correct output |
---|
NO |
user output |
---|
(empty) |
Test 6
Verdict: ACCEPTED
input |
---|
325 a b a e a f a g ... |
correct output |
---|
YES |
user output |
---|
YES |
Test 7
Verdict: RUNTIME ERROR
input |
---|
325 a c a e a g a h ... |
correct output |
---|
NO |
user output |
---|
(empty) |
Test 8
Verdict: RUNTIME ERROR
input |
---|
0 dlkinfmdyjaofxbccwhhbxzartqwdr... |
correct output |
---|
YES |
user output |
---|
(empty) |
Test 9
Verdict: RUNTIME ERROR
input |
---|
0 bxisdrdpgcsnnvhnfgimivzqpqjwqc... |
correct output |
---|
NO |
user output |
---|
(empty) |
Test 10
Verdict: RUNTIME ERROR
input |
---|
0 mrwduerojcguvxzmbomfsainvqehsl... |
correct output |
---|
NO |
user output |
---|
(empty) |