Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
62858367 Practice:
mudit
1236D - 30 Python 3 Runtime error on test 6 155 ms 5000 KB 2019-10-18 13:02:26 2019-10-18 13:02:26
→ Source
n, m, k = map(int, input().split())

maze = [[0] * m for _ in range(n)]

count = 0

# mm = [[1,2,3], [4,5,6],[7,8,9]]
# for i in mm:
#     print(i)
#
#
# mm[2][2] = 10
#


for _ in range(k):
    xi, yi = map(int, input().split())
    maze[xi - 1][yi - 1] = 1
    count += 1

# maze[1][0] = 1

# print(count)

result = n * m


def rightface(face):
    return (face + 1) % 4


def nextst(face, xi, yi):
    if face == 0:
        yi += 1
    elif face == 1:
        xi += 1
    elif face == 2:
        yi += -1
    else:
        xi -= 1

    return face, xi, yi


def nextrt(face, xi, yi):
    face = rightface(face)

    return nextst(face, xi, yi)


def walk(f, xi, yi, count):
    if xi < 0 or yi < 0 or xi >= n or yi >= m or maze[xi][yi] == 1:
        # print(count)
        return False

    maze[xi][yi] = 1
    count += 1
    if count == result:
        # print(count)
        return True

    # walk st
    f2, x2, y2 = nextrt(f, xi, yi)

    a1 = walk(f2, x2, y2, count)

    f1, x1, y1 = nextst(f, xi, yi)

    a2 = walk(f1, x1, y1, count)

    maze[xi][yi] = 0

    # print(count)
    return a1 or a2


ans = walk(0, 0, 0, count)
if ans:
    print('Yes')
else:
    print('No')
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details