TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W = map(int, input().split())

edge = [["." for _ in range(W+2)]]
center = [["."] + list(input()) + ["."] for i in range(H)]
A_array = edge + center + edge

def is_there_OK_move(before_i,before_j,before_move,route):
    if before_move == "right":
        i = before_i
        j = before_j + 1
    elif before_move == "down":
        i = before_i + 1
        j = before_j
    
    if i == H and j == W:
        return route
    else:
        up = A_array[i-1][j]
        down = A_array[i+1][j]
        right = A_array[i][j+1]
        left = A_array[i][j-1]

        if (down == right == "#") or (before_move == "right" and up == "#") or (before_move == "down" and left == "#"):
            return -1
        else:
            route.append((i,j))
            if down == "#":
                return is_there_OK_move(i,j,"down",route)
            elif right == "#":
                return is_there_OK_move(i,j,"right",route)

route = is_there_OK_move(0,1,"down",[(0,1)])

if route == -1:
    print("Imossible")
else:           
    print("Ppossible")

H,W = map(int, input().split())

edge = [["." for _ in range(W+2)]]
center = [["."] + list(input()) + ["."] for i in range(H)]
A_array = edge + center + edge

def is_there_OK_move(before_i,before_j,before_move):
    if before_move == "right":
        i = before_i
        j = before_j + 1
    elif before_move == "down":
        i = before_i + 1
        j = before_j

    up = A_array[i-1][j]
    down = A_array[i+1][j]
    right = A_array[i][j+1]
    left = A_array[i][j-1]
    
    if i == H and j == W:
        if up == left == "#":
            return -1
        else:
            return 1
    elif (down == right == "#") or (before_move == "right" and up == "#") or (before_move == "down" and left == "#"):
        return -1
    else:
        if down == "#":
            return is_there_OK_move(i,j,"down")
        elif right == "#":
            return is_there_OK_move(i,j,"right")


ans = is_there_OK_move(0,1,"down")

if ans == 1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
import sys

IMPOSSIBLE = 'IMPOSSIBLE'
POSSIBLE = 'POSSIBLE'

def solve():
    H, W = map(int, sys.stdin.readline().split())
    lines = list(map(lambda s: s.rstrip(), sys.stdin.readlines()))
    maxs = []
    mins = []
    for line in lines:
        m = -1
        for i, w in enumerate(line):
            if w == '#':
                m = i
        maxs.append(m)
        m = len(line)
        for i, w in reversed(list(enumerate(line))):
            if w == '#':
                m = i
        mins.append(m)

    for min, max in zip(mins, maxs):
        if '.' in lines[min:max+1]:
            return IMPOSSIBLE

    for min, max in zip(mins[1:], maxs):
        if min != max:
            return IMPOSSIBLE

    return POSSIBLE

print(solve())


import sys

IMPOSSIBLE = 'IMPOSSIBLE'
POSSIBLE = 'POSSIBLE'

def solve():
    H, W = map(int, sys.stdin.readline().split())
    lines = list(map(lambda s: s.rstrip(), sys.stdin.readlines()))
    maxs = []
    mins = []
    for line in lines:
        m = -1
        for i, w in enumerate(line):
            if w == '#':
                m = i
        maxs.append(m)
        m = len(line)
        for i, w in reversed(list(enumerate(line))):
            if w == '#':
                m = i
        mins.append(m)

    for i, (min, max) in enumerate(zip(mins, maxs)):
        if '.' in lines[i][min:max+1]:
            return IMPOSSIBLE

    for min, max in zip(mins[1:], maxs):
        if min != max:
            return IMPOSSIBLE

    return POSSIBLE

print(solve())


import sys

IMPOSSIBLE = 'Impossible'
POSSIBLE = 'Possible'

def solve():
    H, W = map(int, sys.stdin.readline().split())
    lines = list(map(lambda s: s.rstrip(), sys.stdin.readlines()))
    maxs = []
    mins = []
    for line in lines:
        m = -1
        for i, w in enumerate(line):
            if w == '#':
                m = i
        maxs.append(m)
        m = len(line)
        for i, w in reversed(list(enumerate(line))):
            if w == '#':
                m = i
        mins.append(m)

    for i, (min, max) in enumerate(zip(mins, maxs)):
        if '.' in lines[i][min:max+1]:
            return IMPOSSIBLE

    for min, max in zip(mins[1:], maxs):
        if min != max:
            return IMPOSSIBLE

    return POSSIBLE

print(solve())


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W = map(int, input().split())
A = [input() for _ in range(H)]

if H + W == sum(a.count('#') for a in A):
    print('Possible')
else:
    print('Impossible')


H, W = map(int, input().split())
A = [input() for _ in range(H)]

if H + W - 1 == sum(a.count('#') for a in A):
    print('Possible')
else:
    print('Impossible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int, input().split())
s=[list(input()) for _ in range(h)]
c=0
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      c+=1
if c==h+w-2:
  print("Possible")
else:
  print("Impossible")

h,w=map(int, input().split())
s=[list(input()) for _ in range(h)]
c=0
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      c+=1
if c==h+w-1:
  print("Possible")
else:
  print("Impossible")


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):

def dfs(x, y): 
    if x == h-1 and y == w-1:
        a[x][y] = "."
        print(a)
        for i in range(h):
            if "#" in a[i]:
                print("Impossible")
                exit()
        print("Possible")
        exit()
    
    if a[x][y] == "#":
        a[x][y] = "."

    if y+1 < w and a[x][y+1] != ".":
        dfs(x, y+1)
    
    if x+1 < h and a[x+1][y] != ".":
        dfs(x+1, y)

h, w = map(int, input().split())
a = []
for i in range(h):
    a.append(list(input()))

dfs(0, 0)

print(a)

for i in range(h):
    if "#" in a[i]:
        print("Impossible")
        exit()
print("Possible")

h, w = map(int, input().split())
cnt = 0
for i in range(h):
    cnt += list(input()).count("#")

if cnt == h+w-1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int,input().split())
c=0
for i in range(h):
  c=input().count("#")
print("Possible" if c=h+w-1: "Impossible")

h,w=map(int,input().split())
c=0
for i in range(h):
  c+=input().count("#")
print("Possible" if c=h+w-1 else "Impossible")


h,w=map(int,input().split())
c=0
for i in range(h):
  c+=input().count("#")
print("Possible" if c=h+w-1: "Impossible")


h,w=map(int,input().split())
c=0
for i in range(h):
  c+=input().count("#")
print("Possible" if c==h+w-1 else "Impossible")


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
*t,=open(0)
print(["Imp", "P"][int(t[0][0])+int(t[0][2])-1==sum(s.count("#")for s in t[1:])]+"oosible")

*t,=open(0)
print(["Imp", "P"][int(t[0][0])+int(t[0][2])-1==sum(s.count("#")for s in t[1:])]+"ossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
cnt=0
for _ in range(H):
  cnt+=l.count("#")
if cnt==H+W-1:
  print("Possible")
else:
  print("Impossible")

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
cnt=0
for _ in range(H):
  l = input()
  cnt+=l.count("#")
if cnt==H+W-1:
  print("Possible")
else:
  print("Impossible")

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
import copy
h,w=map(int,input().split())

def fun(aa,x,y):
    a=copy.deepcopy(aa)

    if h<=y or w<=x:
        return False

    if y==h-1 and x==w-1:
        count = 0
        for i in a:
            count += i.count('#')
        if count==1:
            return True
        else:
            return False

    if a[y][x]!="#":
        return False

    a[y][x]="."

    if fun(a,x+1,y) or fun(a,x,y+1):
        return True

    return False

a=[["" for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        a[i][j]=s[j]


import copy
h,w=map(int,input().split())

def fun(aa,x,y):
    a=copy.deepcopy(aa)

    if h<=y or w<=x:
        return False

    if y==h-1 and x==w-1:
        count = 0
        for i in a:
            count += i.count('#')
        if count==1:
            return True
        else:
            return False

    if a[y][x]!="#":
        return False

    a[y][x]="."

    if fun(a,x+1,y) or fun(a,x,y+1):
        return True

    return False

a=[["" for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        a[i][j]=s[j]



print("Possible" if fun(a,0,0) else "Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
height , width = map(int,input().split())
grid = [input() for i in range(height)]
count = 0
for h in range(height):
    for w in range(width):
        if grid[h][w] == '#':
            count = count + 1

if count == height + width - 1:
    print("Posible")

else:
    print("Impossible")


H, W = map(int, input().split())
As =[input() for _ in range(H)]
cnt = 0
for i in range(H):
    for j in range(W):
        if As[i][j] == '#':
            cnt += 1
if cnt == H+W-1:
    print('Possible')
else:
    print('Impossible')


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
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")

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
    check = 0
    count2 = 0
    for j in range(w):
        if a[i][j] == "#":
            if a[i][j] == a[i + 1][j]:
                count += 1
                if check == 0:
                    check = 1
                    if count2 > 0:
                        count = 2
                        break
        else:
            if a[i + 1][j] == "#":
              count2 += 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
    count = 0
    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])
                count += 1
    if count > 1:
        break

if flag:
    print("Possible")
else:
    print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
import itertools
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append(list(input()))

flag = False
for j in (itertools.product([0,1],repeat=(H+W-2))):
    route_flag = True
    right = 0
    down  = 0
    for k in j:
        if k == 1:
            right += 1
        else:
            down += 1
        if data[down][right] == ".":
            route_flag = False
    if foute_flag:
        flag = True
    
if data[0][0] == ".":
    flag = False

if flag:
    print("Possible")
else:
    print("Impossible")

import itertools
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(H):
    data.append(list(input()))

right = 0
down  = 0
for i in data:
    for j in range(0,W-1):
        if i[j] == "#" and i[j+1] == "#":
            right += 1

data_t = []
for i in range(W):
    row = []
    for vector in data:
        row.append(vector[i])
    data_t.append(row)

for i in data_t:
    for j in range(0,H-1):
        if i[j] == "#" and i[j+1] == "#":
            down += 1

if down == H-1 and right == W-1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
W, H = map(int, input().split())
L = [input() for _ in range(H)]

count = 0
for i in range(H):
  for j in range(W):
    if L[i][j] == '#':
      count += 1
      
if count == W + H - 1:
  print('Possible')
else:
  print('Impossible')

H, W = map(int, input().split())
L = [input() for _ in range(H)]

count = 0
for i in range(H):
  for j in range(W):
    if L[i][j] == '#':
      count += 1
      
if count == W + H - 1:
  print('Possible')
else:
  print('Impossible')

Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
# A - Shik and Stone
H,W = map(int,input().split())
mp = [list(input()) for _ in range(H)]

dw = [1,0]
dh = [0,1]

seen = [[False]*W for _ in range(H)]
def dfs(h,w):
    seen[h][w] = True
    
    nxt_h = h + dh[0]
    nxt_w = w + dw[0]
    if not(-1<nxt_w<W): 
        return
    
    if mp[nxt_h][nxt_w] == '.':
        nxt_h = h + dh[1]
        nxt_w = w + dw[1]
    if not(-1<nxt_h<H):
        return
    if (seen[nxt_h][nxt_w] == True) or (mp[nxt_h][nxt_w] == '.'):
        return
    dfs(nxt_h,nxt_w)
        
dfs(0,0)
for S in seen:
    print(S)

result = 'Possible'
for h in range(H):
    for w in range(W):
        if mp[h][w] == '#':
            if seen[h][w] == False:
                result = 'Impossible'
                break
print(result)

# A - Shik and Stone
import sys
sys.setrecursionlimit(10**7)
H,W = map(int,input().split())
mp = [list(input()) for _ in range(H)]

dw = [1,0]
dh = [0,1]

seen = [[False]*W for _ in range(H)]
def dfs(h,w):
    seen[h][w] = True
    
    nxt_h = h + dh[0]
    nxt_w = w + dw[0]
    if not(-1<nxt_w<W): 
        return
    
    if mp[nxt_h][nxt_w] == '.':
        nxt_h = h + dh[1]
        nxt_w = w + dw[1]
    if not(-1<nxt_h<H):
        return
    if (seen[nxt_h][nxt_w] == True) or (mp[nxt_h][nxt_w] == '.'):
        return
    dfs(nxt_h,nxt_w)

result = 'Possible'
for h in range(H):
    for w in range(W):
        if mp[h][w] == '#':
            if seen[h][w] == False:
                result = 'Impossible'
                break
print(result)

# A - Shik and Stone
import sys
sys.setrecursionlimit(10**7)
H,W = map(int,input().split())
mp = [list(input()) for _ in range(H)]

dw = [1,0]
dh = [0,1]

seen = [[False]*W for _ in range(H)]
def dfs(h,w):
    seen[h][w] = True
    
    nxt_h = h 
    nxt_w = w + 1   
    
    if  not(-1<nxt_w<W) or mp[nxt_h][nxt_w] == '.':
        nxt_h = h + 1
        nxt_w = w 
    
    if not(-1<nxt_h<H):
        return
    if (seen[nxt_h][nxt_w] == True) or (mp[nxt_h][nxt_w] == '.'):
        return
    dfs(nxt_h,nxt_w)
        
dfs(0,0)

result = 'Possible'
for h in range(H):
    for w in range(W):
        if mp[h][w] == '#':
            if seen[h][w] == False:
                result = 'Impossible'
                break
print(result)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W = map(int,input().split())
A = [list(str(input())) for _ in range(H)]
for i in range(H):
  A[i] += '.'
A += [list('.'*(W+1))]
y,x = 0,0
ans = 'Impossible'
while y < H and x < W:
  if A[y+1][x] == '#' and A[y][x+1] == '#':
    break
  elif A[y+1][x] == '#':
    y += 1
  elif A[y][x+1] == '#':
    x += 1
  else:
    break
  print(y,x)
  if y == H-1 and x == W-1:
    ans = 'Possible'
    break
print(ans)

H,W = map(int,input().split())
A = [list(str(input())) for _ in range(H)]
for i in range(H):
  A[i] += '.'
A += [list('.'*(W+1))]
y,x = 0,0
ans = 'Impossible'
while y < H and x < W:
  if A[y+1][x] == '#' and A[y][x+1] == '#':
    break
  elif A[y+1][x] == '#':
    if '#' in A[y][x+1:] or '#' in A[y+1][:x]:
      break
    y += 1
  elif A[y][x+1] == '#':
    x += 1
  else:
    break
  if y == H-1 and x == W-1:
    ans = 'Possible'
    break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int,input().split())
count=0
for i in range(h):
  a=input()
  count = a.count("#")
if count == h + w - 1:
  print("Possible")
else:
  print("Impossible")

h,w=map(int,input().split())
count=0
for i in range(h):
  a=input()
  count += a.count("#")
if count == h + w - 1:
  print("Possible")
else:
  print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())
a = [input() for _ in range(h)]
now = 0
ng = 0
for i in range(h):
    # print(now)
    
    extended = 0
    if a[i][now] != "#" or "#" in a[i][:now]:
        ng = 1
        break
    for j in range(now, w):
        if not extended:
            if a[i][j] == "#":
                now = j
            else:
                extended = 1
        else:
            if a[i][j] != "#":
                ng = 1
                break
        if i == h - 1 and j == w - 1 and extended == 0:
            print("Possible")
            exit()
    if ng:
        break
if ng:
    print("Impossible")

"""
while True:
    right_most = j
    bit = 0
    for k in range(w):
        if a[i][k] == "#":
            if k < j:
                print("Impossible")
                exit()
            if not bit:
                right_most = k
            else:
                print("Impossible")
                exit()
        else:
            if k > j:
                bit = 1
    j = right_most
    if i == h - 1 and j == w - 1:
        print("Possible")
        exit()
    else:
        down_most = i
        bit = 0
        for k in range(h):
            if a[k][j] == "#":
                if k < i:
                    print("Impossible")
                    exit()
                if not bit:
                    down_most = k
                else:
                    print("Impossible")
                    exit()
            else:
                if k > i:
                    bit = 1
        i = down_most
        if i >= h - 1 and j >= w - 1:
            print("Possible")
            exit()"""


h, w = map(int, input().split())
a = [input() for _ in range(h)]
now = 0
ng = 0
for i in range(h):
    # print(now)
    
    extended = 0
    if a[i][now] != "#" or "#" in a[i][:now]:
        ng = 1
        # print(i, now)
        break
    for j in range(now, w):
        if not extended:
            if a[i][j] == "#":
                now = j
            else:
                extended = 1
        else:
            if a[i][j] == "#":
                #print(i, j)
                ng = 1
                break
        if i == h - 1 and j == w - 1 and a[i][j] == ".":
            ng = 1
    if ng:
        break
if ng:
    print("Impossible")
else:
    print("Possible")


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
from collections import deque
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

queue = deque()
queue.append([0, 0])
visited = [[False] * w for _ in range(h)]
visited[0][0] = True

def judge():
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#" and not visited[i][j]:
                return False
    return True
def bfs(queue):
    while len(queue) > 0:
        n_y, n_x = queue.popleft()

        if a[n_y][n_x + 1] == "#" and a[n_y + 1][n_x] == "#":
            print("Impossible")
            exit()
        for i, j in [[0, 1], [1, 0]]:
            y, x = n_y + i, n_x + j
            if 0 <= x < w and 0 <= y < h:
                if x != w - 1 and y != h -1:
                    if a[y][x] == "#" :
                        queue.append([y, x])
                        visited[y][x] = True
    for i in range(h):
        print(visited[i])
    print("Possible" if judge() else "Impossible")
bfs(queue)


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

queue = deque()
queue.append([0, 0])
visited = [[False] * w for _ in range(h)]
visited[0][0] = True

def judge():
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#" and not visited[i][j]:
                return False
    
    return True

def bfs(queue):
    while len(queue) > 0:
        n_y, n_x = queue.popleft()
        for i, j in [[0, 1], [1, 0]]:
            y, x = n_y + i, n_x + j
            if 0 <= x < w and 0 <= y < h:
                if x != w - 1 and y != h -1:
                    if a[y][x + 1] == "#" and a[y + 1][x] == "#":
                        print("Impossible")
                        exit()
                if a[y][x] == "#" :
                    queue.append([y, x])
                    visited[y][x] = True
    
    
    for i in range(h):
        print(visited[i])
    
    print("Possible" if judge() else "Impossible")
bfs(queue)


h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

cnt = sum([row.count("#") for row in a])
print("Possible" if cnt == h + w - 1 else "Impossible")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())
a = [input() for i in range(h)]

dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]

def check(y, x):
    for i in range(4):
        cnt = 0
        ny = y + dy[i]
        nx = x + dx[i]
        if (ny < 0) or (ny >= h) or (nx < 0) or (nx >= w):
            continue
        if a[ny][nx] == '#':
            cnt+=1
    if cnt >= 3:
        return 1;
    else:
        return 0;

def dfs(y, x):
    if a[y][x] == '#':
        return 0
    if (y == h - 1) and (x == w - 1):
        return 1

    dfs(y + 1, x)
    dfs(y, x + 1)
    return 0

ans = "Possible"
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            if check(i,j):
                ans = "Inpossible"

if not dfs(0, 0):
    ans = "Inpossible"

print (ans)


h, w = map(int, input().split())
a = [list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            a[i][j] = '.'
            break

for i in range(1,w):
    for j in range(h):
        if a[j][i] == '#':
            a[j][i] = '.'
            break

def check():
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                return 0;
    return 1;

if check():
    print ("Possible")
else :
    print ("Impossible")


Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W = map(int, input().split())
ban = [list(input()) for _ in range(H)]
cnt = 0
for i in range(H):
    cnt = ban[i].count("#")
if cnt == H + W - 1:
    print("Possible")
else:
    print("Impossible")

H, W = map(int, input().split())
ban = [list(input()) for _ in range(H)]
cnt = 0
for i in range(H):
    for j in range(W):
        if ban[i][j] == "#":
            cnt += 1
if cnt == H + W - 1:
    print("Possible")
else:
    print("Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w=map(int,input().split())
d='.'*(w+2)
a=[d]
for _ in range(h):
  s='.'+input()+'.'
  a.append(s)
a.append(d)
x='Possible'
a[h][w+1]='#'
for i in range(1,w+1):
  for j in range(1,h+1):
    if a[j][i]=='#':
      if a[j][i+1]==a[j+1][i]:
        x='Impossible'
        break
print(x)

h,w=map(int,input().split())
a=[list(input())+'.' for _ in range(h)]
d='.'*(w+1)
a.append(d)
x=1
i=0;j=0
while i!=h-1 or j!=w-1:
  if a[i+1][j]=='#':
    if a[i][j+1]=='#':
      x=0
      break
    else:
      i=i+1
      a[i][j]='.'
  else:
    if a[i][j+1]=='.':
      x=0
      break
    else:
      j=j+1
      a[i][j]='.'
if x==1:
  if '#' in a:
    x=0
print('Possible' if x==1 else 'Impossible')

h,w=map(int,input().split())
a=[list(input()+'.') for _ in range(h)]
d=['.']*(w+1)
a.append(d)
x=1
i=0;j=0
a[0][0]='.'
while i!=h-1 or j!=w-1:
  if a[i+1][j]=='#':
    if a[i][j+1]=='#':
      x=0
      break
    else:
      i=i+1
      a[i][j]='.'
  else:
    if a[i][j+1]=='.':
      x=0
      break
    else:
      j=j+1
      a[i][j]='.'
if x==1:
  for k in range(h):
    if '#' in a[k]:
      x=0
      break
print('Possible' if x==1 else 'Impossible')

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W = map(int, input().split())
fields = [list(input()) for i in range(H)]

for f in fields:
    cnt += f.count("#")
if cnt == H + W - 1: 
    print("Possible")
else:
    print("Impossible")

H,W = map(int, input().split())
fields = [list(input()) for i in range(H)]
cnt = 0
for f in fields:
    cnt += f.count("#")
if cnt == H + W - 1: 
    print("Possible")
else:
    print("Impossible")


Verdicts: Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H, W = map(int, input().split())
A = [input() for _ in range(H)]
pos = {x:0, y:0}
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

H, W = map(int, input().split())
A = [input() for _ in range(H)]
pos = {x:0, y:0}
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

H, W = map(int, input().split())
A = [input() for _ in range(H)]
cnt = 0
for i in range(H):
  cnt += A[i].count('#')

if cnt == (H + W -1):
  print("Possible")
else:
  print("Impossible")

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h, w = map(int, input().split())

A = []
B = ["."] * (w + 2)
A.append(B)
temp = 0
for i in range(h):
    T = ['.'] + list(input()) + ['.']
    A.append(T)
    temp += T.count('#')
A.append(B)

t = 1
print(A)
x = 1
y = 1
ans = 0
while t:
    if A[x][y] == '#':
        C = []
        C.append(A[x][y + 1])
        C.append(A[x+1][y])
        if C.count('#') > 1:
            t = 0
        else:
            A[x][y] = '?'
            if A[x][y+1] == '#':
                y = y + 1
            else:
                x = x + 1
            ans += 1
    else:
        t = 0

print("Possible" if ans == temp else "Impossible")

h, w = map(int, input().split())

A = []
B = ["."] * (w + 2)
A.append(B)
temp = 0
for i in range(h):
    T = ['.'] + list(input()) + ['.']
    A.append(T)
    temp += T.count('#')
A.append(B)

t = 1
x = 1
y = 1
ans = 0
while t:
    if A[x][y] == '#':
        C = []
        C.append(A[x][y + 1])
        C.append(A[x+1][y])
        if C.count('#') > 1:
            t = 0
        else:
            A[x][y] = '?'
            if A[x][y+1] == '#':
                y = y + 1
            else:
                x = x + 1
            ans += 1
    else:
        t = 0

print("Possible" if ans == temp else "Impossible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
h,w = map(int,input().split())
l = []
for _ in range(h):
    a = list(map(str,input()))
    l.append(a)

tmp = 0

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            if j < tmp:
                print("Impossible")
                exit()
            else:
                tmp = j
        print(tmp)

print("Possible")

h,w = map(int,input().split())
l = []
for _ in range(h):
    a = list(map(str,input()))
    l.append(a)

tmp = 0

for i in range(h):
    for j in range(w):
        if l[i][j] == "#":
            if j < tmp:
                print("Impossible")
                exit()
            else:
                tmp = j


print("Possible")

Verdicts: Wrong Answer

Accepted
Problem: We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell).  You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.

Submission attempts (in order):
H,W = map(int,input().split())
GRID = [list(input()) for _ in range(H)]

def dfs(h,w,c):
  if h == H - 1 and w == W - 1:
    return c + 1

  if H - 1 < h or W -1 < w:
    return 0
  
  if GRID[h][w] != "#":
    return 0
  
  
  right = dfs(h+1,w,c+1)
  down = dfs(h,w+1,c+1)
  c += max(right,down)

  return c

NUM = sum([GRID[x].count("#") for x in range(H)])

n = dfs(0,0,0)

if n == NUM:
  print("Possible")
else:
  print("Impossible")





H,W = map(int,input().split())
GRID = [list(input()) for _ in range(H)]

def dfs(h,w,c):
  if h == H - 1 and w == W - 1:
    return c + 1
  
  if GRID[h][w] != "#":
    return 0
  
  if H - 1 < h or W -1 < w:
    return 0
  
  right = dfs(h+1,w,c+1)
  down = dfs(h,w+1,c+1)
  c += max(right,down)

  return c

NUM = sum([GRID[x].count("#") for x in range(H)])

n = dfs(0,0,0)

if n == NUM:
  print("Possible")
else:
  print("Impossible")





H,W = map(int,input().split())
GRID = [list(input()) for _ in range(H)]

def dfs(h,w,c):
  if h == H - 1 and w == W - 1:
    return c + 1

  if H - 1 < h or W -1 < w:
    return 0
  
  if GRID[h][w] != "#":
    return 0
  
  
  right = dfs(h+1,w,c+1)
  down = dfs(h,w+1,c+1)

  return max(right,down)

NUM = sum([GRID[x].count("#") for x in range(H)])

n = dfs(0,0,0)

if n == NUM:
  print("Possible")
else:
  print("Impossible")





Verdicts: Wrong Answer

Runtime Error

Accepted