Submission #979570


Source Code Expand

from collections import deque
h, w =  map(int, input().split())
a = [list(input()) for i in range(h)]
mv = [[1, 0], [0, 1]]

sx, sy = 0, 0
gx, gy = h - 1, w - 1
nxt = deque()
nxt.appendleft([sx, sy])

for i in range(h - 1):
    count = 0
    for j in range(w):
        if a[i][j] == a[i + 1][j]:
            count += 1
    if count > 1:
        nxt.clear()
        break
        
flag = 0
while len(nxt) > 0:
    tmp = nxt.pop()
    nwx, nwy = tmp[0], tmp[1]
    if nwx == gx and nwy == gy:
        flag = 1
        break
    for i in range(2):
        tmpx = mv[i][0] + nwx
        tmpy = mv[i][1] + nwy
        if tmpy < w and tmpx < h:
            if a[tmpx][tmpy] == '#':
                nxt.appendleft([tmpx, tmpy])
if flag:
    print("Possible")
else:
    print("Impossible")

Submission Info

Submission Time
Task A - Shik and Stone
User ka24
Language Python (3.4.3)
Score 0
Code Size 816 Byte
Status WA
Exec Time 29 ms
Memory 3444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 200
Status
AC × 2
WA × 1
AC × 12
WA × 10
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, example0.txt, example1.txt, example2.txt
Case Name Status Exec Time Memory
000.txt AC 29 ms 3444 KB
001.txt AC 25 ms 3316 KB
002.txt AC 26 ms 3316 KB
003.txt AC 26 ms 3316 KB
004.txt AC 26 ms 3316 KB
005.txt AC 26 ms 3316 KB
006.txt AC 26 ms 3316 KB
007.txt AC 26 ms 3316 KB
008.txt AC 26 ms 3316 KB
009.txt AC 26 ms 3316 KB
010.txt WA 26 ms 3316 KB
011.txt WA 26 ms 3316 KB
012.txt WA 26 ms 3316 KB
013.txt WA 26 ms 3316 KB
014.txt WA 26 ms 3316 KB
015.txt WA 25 ms 3316 KB
016.txt WA 25 ms 3316 KB
017.txt WA 25 ms 3316 KB
018.txt WA 25 ms 3316 KB
example0.txt WA 25 ms 3316 KB
example1.txt AC 25 ms 3316 KB
example2.txt AC 25 ms 3316 KB