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):
import sys
sys.setrecursionlimit(10**6)

def dfs(x, y, ans):
    if a[x][y] == ".":
        return
    elif [x, y] == [h, w] or cnt > ans+1:
        if ans + 1 == cnt:
            print("Possible")
        else:
            print("Impossible")
        exit()

    for v in [[1, 0], [0, 1], [0, -1], [-1, 0]]:
        dfs(x + v[0], y + v[1], ans + 1)

h, w = map(int, input().split())
a = [["."]*w]
a.extend([list("." + input() + ".") for x in range(h)])
a.append(["."]*w)
cnt = 0
for i in range(1,h+1):
    cnt += a[i].count("#")
dfs(1, 1 , 0)


def dfs(A, chk):
    if a[A[-1][0]][A[-1][1]] == ".":
        return
    elif A[-1] == [h, w]:
        if len(A) == cnt and chk == 0:
            print("Possible")
        else:
            print("Impossible")
        exit()

    for v in [[1, 0], [0, 1], [0, -1], [-1, 0]]:
        tmp = [A[-1][0] + v[0], A[-1][1] + v[1]]
        if tmp not in A:
            A.append(tmp)
            if v in [[0, -1], [-1, 0]]:
                dfs(A, chk + 1)
            else:
                dfs(A, chk)                
            A.pop()

h, w = map(int, input().split())
a = [["."]*w]
a.extend([list("." + input() + ".") for x in range(h)])
a.append(["."]*w)
cnt = 0
for i in range(1,h+1):
    cnt += a[i].count("#")
dfs([[1, 1]], 0)


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 = [list(input()) for _ in range(H)]

ads = [(0, 1), (1, 0), (0, -1), (-1, 0)]
can_moves = {(0, 1), (1, 0)}

def dfs(this_pos):
    this_x, this_y = this_pos

    count = 0
    for ad in ads:
        ad_x, ad_y = ad
        x, y = pos = this_x+ad_x, this_y+ad_y
        if not (0 <= x < W and 0<= y < H):
            continue
        if A[y][x] == ".":
            continue
        A[y][x] = "."
        dfs(pos)
        count += 1
        if count >= 2:
            print("Impossible")
            exit()

dfs((0, 0))

if A[-1][-1] == ".":
    print("Possible")
else:
    print("Impossible")

h,w=map(int,input().split());print("IPmopsossisbilbel e"[open(0).read().count("#")==h+w-1::2])

h,w=map(int,input().split());print("P"*(open(0).read().count("#")==h+w-1)or"Imp"+"ossible")


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

print(["Impossible", "Possible"]["".join(A).count("#")==H+W-1])

Verdicts: Wrong Answer

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):
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = rl()
A = [list(rs()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            A[i][j] = 1
        else:
            A[i][j] = 0
    A[i].append(0)            
A.append([0] * (W + 1))
bool = True

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            if A[i+1][j] + A[i][j+1] != 1:
                bool = False
        if i == H - 1 and j == W - 1:
            if A[i-1][j] + A[i][j-1] != 1:
                bool = False
        if A[i][j] == 1:
            if A[i+1][j] + A[i][j+1] != 1:
                bool = False
            if A[i-1][j] + A[i][j-1] != 1:
                bool = False

print('Possible' if bool else 'Impossible')

import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = rl()
A = [list(rs()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            A[i][j] = 1
        else:
            A[i][j] = 0
    A[i].append(0)            
A.append([0] * (W + 1))
bool = True

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            if A[i+1][j] + A[i][j+1] != 1:
                bool = False
            continue
        if i == H - 1 and j == W - 1:
            if A[i-1][j] + A[i][j-1] != 1:
                bool = False
            continue
        if A[i][j] == 1:
            if A[i+1][j] + A[i][j+1] != 1:
                bool = False
            if A[i-1][j] + A[i][j-1] != 1:
                bool = False

print('Possible' if bool 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):
import sys
f=[[]]*8
h,w=map(int,input().split())
for i in range(h):
  inv=input()
  for j in range(len(inv)):
    if inv[j]=="#":f[i].append(j)
c=0
for i in f:
  if c!=i[0]:
    print("Impossible");sys.exit()
  if i[-1]-i[0]>=len(i):print("Impossible");sys.exit()
  c=i[-1]
print("Possible")

import sys
h,w=map(int,input().split())
f=[[] for i in range(h)]
for i in range(h):
  inv=input()
  for j in range(w):
    if inv[j]=="#":
      f[i].append(j)
c=0
for i in f:
  if c!=i[0]:
    print("Impossible");sys.exit()
  if i[-1]-i[0]>=len(i):print("Impossible");sys.exit()
  c=i[-1]
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, *A = open(0).read().split()
if A.count('#') == int(H) * int(W) - 1:
    print('Possible')
else:
    print('Impossible')

H, W, A = open(0).read().split(maxsplit=2)
if A.count('#') == int(H) + int(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):
print("Impossible")

#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

h = 0
w = 0
A[0][0]="."

while not(h==H-1 and w==W-1):
    # print(h,w)
    if h<H-1 and w<W-1 and A[h+1][w]=="#" and A[h][w+1]=="#":
        print("Impossible")
        break

    elif h<H-1 and A[h+1][w]=="#":
        h += 1
        A[h][w] = "."

    elif w<W-1 and A[h][w+1]=="#":
        w += 1
        A[h][w] = "."
    else:
        print("Impossible")
        break

else:
    flg = 0
    for h in range(H):
        for w in range(W):
            if A[h][w]=="#":
                flg = 1
                break
    else:
        if flg:
            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):
N = input()
l = input().split()

N=int(N)
a=range(1,N+1)
b=range(1,N+1)
a=[i*N for i in a]
b=[i*N for i in b]
b.reverse()

c=0
for i in l:
    i=int(i)
    b[i-1]+=c
    c+=1

for i in a:
    print(i,end=" ")
print("")
for i in b:
    print(i,end=" ")


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    h,w = list(map(int, input().split()))
    a = [input() for _ in range(h)]
    c = 0
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                c += 1
    if c == h + w -1:
        return 'Possible'
    return 'Impossible'


print(f())


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 i in range(h)]
a_count = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            a_count += 1
if a_count == (h+w)-1:
    print('Posiible')
else:
    print('Impossible')


h,w = map(int,input().split())
a = [input() for i in range(h)]
a_count = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            a_count += 1
if a_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):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
s = [input() for i in range(h)]
cnt = 0
for i in s:
    cnt += s.count('#')
if cnt != h+w:
    print('Impossible')
    quit()
for fl in itertools.combinations(range(h+w-2),h-1):
    nx = 0; ny = 0
    for i in range(h+w-2):
        if i in fl:
            ny += 1
        else:
            nx += 1
        if s[ny][nx] == '#':
            continue
        break
    else:
        print('Possible')
        break
else:
    print('Impossible')


from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

h,w = inpl()
s = [list(input()) for i in range(h)]
cnt = 0
for i in s:
    cnt += i.count('#')
if cnt != h+w-1:
    print('Impossible')
    quit()
for fl in itertools.combinations(range(h+w-2),h-1):
    nx = 0; ny = 0
    for i in range(h+w-2):
        if i in fl:
            ny += 1
        else:
            nx += 1
        if s[ny][nx] == '#':
            continue
        break
    else:
        print('Possible')
        break
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 queue

def main():
    H,W = map(int,input().split())
    root = [list(str(input())) for _ in range(H)]
    _long = [[0 for _ in range(W)] for _ in range(H)]
    _long[0][0] = 1
    al = 0
    for i in range(H):
        for j in range(W):
            if root[i][j] == "#":
                al += 1
    
    if al != H+W-1:
        print("IMPOSSIBLE")
        exit()
    
    print("POSSIBLE")
    
if __name__ == "__main__":
    main()


def main():
    H,W = map(int,input().split())
    root = [list(str(input())) for _ in range(H)]
    _long = [[0 for _ in range(W)] for _ in range(H)]
    _long[0][0] = 1
    al = 0
    for i in range(H):
        for j in range(W):
            if root[i][j] == "#":
                al += 1
    
    if al != H+W-1:
        print("Impossible")
        exit()
    
    print("Possible")
    
if __name__ == "__main__":
    main()


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())
HW = [list(map(int,input().split())) for _ in range(h)]
sharp = HW.count('#')
min_root = h + w - 1
if sharp == min_root:
  print('Possible')
else:
  print('Impossible')

h,w = map(int,input().split())
HW = [list(map(str,input().split())) for _ in range(h)]
sharp = 0
for i in range(w):
  for j in range(h):
    if HW[i][j] == '#':
      sharp += 1

min_root = h + w - 1
if sharp == min_root:
  print('Possible')
else:
  print('Impossible')


h,w = map(int,input().split())
HW = [list(map(int,input().split())) for _ in range(h)]
min_root = h + w - 1
if sharp == min_root:
  print('Possible')
else:
  print('Impossible')


def main():
  H, W = list(map(int, input().split()))

  count = 0

  for i in range(H):
    row = input()
    for j in range(W):
      if(row[j] == '#'):
        count += 1

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

if __name__ == "__main__":
  main()


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):
h,w = map(int,input().split())
cou = 0
co = 0
for i in range(h):
    lis = str(input())
    lis = lis + "0"
    if cou == w-1:
        w -= 1
        if lis[min(cou,w-1)] == "#":
            w += 1
            for m in range(w):
                if lis[m] == "#":
                    co += 1
            while lis[cou] == "#" and cou < w:
                cou += 1
            if i == h -1 and cou == w and co == h +(w - 1):
                print("Possible")
                exit()
        else:
            print("Impossible")
            exit()
print("Impossible")

h,w=map(int,input().split())
num=0
s=[str(input()) for i in range(h):]
for i in range(h):
  num+=s[i].count("#")
if num>h+w-1:
  print("Impossible")
  exit()
print("Possible")

h,w=map(int,input().split())
num=0
s=[str(input()) for i in range(h)]
for i in range(h):
  num+=s[i].count("#")
if num>h+w-1:
  print("Impossible")
  exit()
print("Possible")


Verdicts: Wrong Answer

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,*a=open(0);print("IM"*(sum(x.count("#")for x in a)!=eval(h.replace(" ","+"))-1)+"POSSIBLE")

h,*a=open(0);print("Im"*(sum(x.count("#")for x in a)!=eval(h.replace(" ","+"))-1)+"possible")

h,*a=open(0);print(("Imp"*(sum(x.count("#")for x in a)!=eval(h.replace(" ","+"))-1)or"P")+"ossible")

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_lst = []
for i in range(H):
    tmp = list(input())
    A_lst.append(tmp)

print(A_lst)

def judge(A_lst): 
    for i in range(1, H):
        for j in range(1, W):
            if A_lst[i][j-1] == "#" and A_lst[i-1][j] == "#":
                return False
    return True

if judge(A_lst):
    print("Possible")

else:
    print("Impossible")

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

A_lst = []
for i in range(H):
    tmp = list(input())
    A_lst.append(tmp)

#print(A_lst)

def judge(A_lst): 
    for i in range(1, H):
        for j in range(1, W):
            if A_lst[i][j-1] == "#" and A_lst[i-1][j] == "#":
                return False
    return True

if judge(A_lst):
    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 = list(map(int, input().split()))

grid = [input() for _ in range(h)]

x = 0
y = 0

while True:
    c = []
    neighbours = 0
    if x != w-1:
        c.append([x+1, y, 1])
    if y != h-1:
        c.append([x, y+1, 3])

    for coords in c:
        if grid[coords[1]][coords[0]] == "#":
            neighbours += 1
            x2 = coords[0]
            y2 = coords[1]

    if neighbours != 1:
        print("Impossible")
        break

    c = []
    neighbours = 0
    if x != 0:
        c.append([x-1, y, 0])
    if y != 0:
        c.append([x, y-1, 2])

    for coords in c:
        if grid[coords[1]][coords[0]] == "#":
            neighbours += 1

    if neighbours > 1:
        print("Impossible")
        break

    if x == w-1 and y == h-1:
        print("Possible")
        break

    x = x2
    y = y2

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

x = 0
y = 0

while True:
    c = []
    neighbours = 0
    if x != w-1:
        c.append([x+1, y, 1])
    if y != h-1:
        c.append([x, y+1, 3])

    for coords in c:
        if grid[coords[1]][coords[0]] == "#":
            neighbours += 1
            x2 = coords[0]
            y2 = coords[1]

    if neighbours != 1 and not (x == w-1 and y == h-1):
        print("Impossible")
        break

    c = []
    neighbours = 0
    if x != 0:
        c.append([x-1, y, 0])
    if y != 0:
        c.append([x, y-1, 2])

    for coords in c:
        if grid[coords[1]][coords[0]] == "#":
            neighbours += 1

    if neighbours > 1:
        print("Impossible")
        break

    if x == w-1 and y == h-1:
        print("Possible")
        break

    x = x2
    y = y2

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)]

def printmap(A):
  print('=====')
  for i in range(len(A)):
    print(A[i])

i, j = 0, 0
Goal = False
while True:
  if j == 0:
    A[i] = '.' + A[i][j+1:]
  elif j == W-1:
    A[i] = A[i][:j] + '.'
  else:
    A[i] = A[i][:j] + '.' + A[i][j+1:]
  printmap(A)
  right, down = False, False
  if i <= H-2:
    if A[i+1][j] == '#':
      down = True
  if j <= W-2:
    if A[i][j+1] == '#':
      right = True
  if i >= 1:
    if A[i-1][j] == '#':
      break
  if j >= 1:
    if A[i][j-1] == '#':
      break
  if right and down:
    break
  if right:
    j += 1
  if down:
    i += 1
  if i == H-1 and j == W-1:
    Goal = True
    break

if Goal:
  print('Possible')
else:
  print('Impossible')


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

c = 0
for i in range(H):
  c += A[i].count('#')

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):
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
que = collections.deque()
que.append((0,0))
while que:
  i,j = que.popleft()
  A[i][j] = "."
  if 0 <= i+1 < h:
    if A[i+1][j] == "#":
      que.append((i+1,j))
  continue
  if 0 <= j + 1 < w:
    if A[i][j+1] == "#":
      que.append((i,j+1))
for i in range(h):
  for j in range(w):
    if A[i][j] == "#":
      print("Impossible")
      exit()
print("Possible")
# print(*A,sep="\n")

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
que = collections.deque()
que.append((0,0))
while que:
  i,j = que.popleft()
  A[i][j] = "."
  if 0 <= i+1 < h:
    if A[i+1][j] == "#":
      que.append((i+1,j))
      continue
  if 0 <= j + 1 < w:
    if A[i][j+1] == "#":
      que.append((i,j+1))
# print(*A,sep="\n")
for i in range(h):
  for j in range(w):
    if A[i][j] == "#":
      print("Impossible")
      exit()
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())
A = [list(input()) for _ in range(H)]

i = j = 0

passed = [[None] * W for _ in range(H)]

def dp(i, j):
    global H, W
    passed[i][j] = True
    if i == H - 1 and j == W - 1: return True
    #
    if i + 1 >= H:
        d = False
    else:
        d = (A[i + 1][j] == '#')
    #
    if j + 1 >= W:
        r = False
    else:
        r = (A[i][j + 1] == '#')
    #
    if d and not r:
        return dp(i + 1, j)
    elif not d and r:
        return dp(i, j + 1)
    else:
        return False

if dp(0, 0):
    ans = 'Possible'
    for i in range(H):
        for j in range(W):
            if not visited[i][j] and A[i][j] == '#':
                ans = 'Impossible'
    #
    print(ans)
else:
    print('Impossible')

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

i = j = 0

visited = [[None] * W for _ in range(H)]

def dp(i, j):
    global H, W
    visited[i][j] = True
    if i == H - 1 and j == W - 1: return True
    #
    if i + 1 >= H:
        d = False
    else:
        d = (A[i + 1][j] == '#')
    #
    if j + 1 >= W:
        r = False
    else:
        r = (A[i][j + 1] == '#')
    #
    if d and not r:
        return dp(i + 1, j)
    elif not d and r:
        return dp(i, j + 1)
    else:
        return False

if dp(0, 0):
    ans = 'Possible'
    for i in range(H):
        for j in range(W):
            if not visited[i][j] and A[i][j] == '#':
                ans = 'Impossible'
    #
    print(ans)
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 = [list(input()) for _ in range(H)]

ans = "Impossible"

cnt = 0
for a in A:
    cnt += A.count("#")

if cnt == H + W - 1:
    ans = "Possible"

print(ans)

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

ans = "Impossible"
d = [(1, 0), (0, 1)]


def f(y, x):
    if y == H-1 and x == W-1:
        global ans
        ans = "Possible"
        return
    elif not (0 <= y < H and 0 <= x < W):
        return
    elif A[y][x] == ".":
        return
    
    f(y+1, x)
    f(y, x+1)


f(0, 0)
print(ans)

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

ans = "Impossible"

cnt = 0
for a in A:
    cnt += a.count("#")

if cnt == H + W - 1:
    ans = "Possible"

print(ans)

Verdicts: Wrong Answer

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())

ans = 0
for i in range(h):
  ans += input().count("#")
  print(ans)

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


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

ans = 0
for i in range(h):
  ans += input().count("#")

print("Possible" if h + w - 1 == ans 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):
from collections import deque
H, W = map(int, input().split())
sy,sx = 1,1
gy,gx = H,W
sy-=1
sx-=1
gy-=1
gx-=1
con = [[1,0],[0,1],[-1,0],[0,-1]]
m=[]
d = [[0]*W for _ in range(H)]
for i in range(H):
    a= input()
    m.append(a)
q = deque()
q.append((sy,sx))
s = 0
while len(q)>0:
    y,x = q.popleft()
    if y == gy and x == gx:
        break
    for dx,dy in con:
        if  y+dy>=0 and x+dx >= 0 and y+dy < H and x+dx < W:
            if d[y+dy][x+dx] == 0 and m[y+dy][x+dx] =="#":
                q.append((y+dy,x+dx))
                d[y+dy][x+dx]+=d[y][x]+1
                if dx==-1 or dy == -1:
                    s = 1


if H+W < d[gy][gx] or s == 1:
    print("Impossible")
else:print("Possible")



from collections import deque
H, W = map(int, input().split())
sy,sx = 1,1
gy,gx = H,W
sy-=1
sx-=1
gy-=1
gx-=1
con = [[1,0],[0,1],[-1,0],[0,-1]]
m=[]
d = [[0]*W for _ in range(H)]
for i in range(H):
    a= input()
    m.append(a)
q = deque()
q.append((sy,sx))
d[sy][sx] = 1
s = 0
while len(q)>0:
    y,x = q.popleft()
    if y == gy and x == gx:
        break
    for dx,dy in con:
        if  y+dy>=0 and x+dx >= 0 and y+dy < H and x+dx < W:
            if d[y+dy][x+dx] == 0 and m[y+dy][x+dx] =="#":
                q.append((y+dy,x+dx))
                d[y+dy][x+dx]+=d[y][x]+1
for i in range(H):
    for j in range(W):
        if m[i][j] == "#":s+=1
if H+W < d[gy][gx] or s > d[gy][gx]:
    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):
H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    flag=False
    for j in range(id,W):
      if flag ans s[j]=="#":
        print("Impossible")
        exit(0)
      if s[j]==".":
        flag=True
print("Possible")
  

H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    flag=False
    prev = id
    for j in range(prev,W):
      if flag ans s[j]=="#":
        print("Impossible")
        exit(0)
      if s[j]==".":
        flag=True
print("Possible")
  

H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    for j in range(id,W):
      if s[j]!="#":
        print("Impossible")
        exit(0)
print("Possible")
  

H,W=map(int,input().split())
prev=0
for i in range(H):
  s=input()
  id = s.index("#")
  if id >= prev:
    flag=False
    prev = W-1 - s[::-1].index("#")
    for j in range(id,W):
      if flag and s[j]=="#":
        print("Impossible")
        exit(0)
      if s[j]==".":
        flag=True
  else:
    print("Impossible")
    exit(0)
print("Possible")
  

Verdicts: Runtime Error

Runtime Error

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 numpy as np

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

A = np.zeros([W, H])

for i in range(H):
    A[:, i] = np.array(
            list(map(
                lambda x: 1 if x == "#" else 0, list(input())
                ))
            )

r = np.zeros([H, 2])




import sys


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

    hash = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                hash.append((h, w))

    if hash == []:
        print('Impossible')
        sys.exit()

    s = hash[0]

    nd = ((1, 0), (0, 1))

    q = [s]
    cnt = 1
    while q:
        x0, y0 = q[0]
        del q[0]
        for dx, dy in nd:
            x = x0 + dx
            y = y0 + dy
            if x < H and y < W:
                if A[x][y] == "#":
                    cnt += 1
                    q.append((x, y))
                    break

    if cnt == len(hash):
        print('Possible')
    else:
        print('Impossible')

main()


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())
f = [input()for _ in range(h)]
res = 0
for  i in range(h):
    res += f[i].count('#')
if res  == h+w-1:print('Yes')
else:print('No')

h,w = map(int,input().split())
field = [input()for _ in range(h)]
vec = [(1,0),(0,1)]
stack = [(0,0)]
ok = True
while stack:
    next = []
    for x,y in stack:
        cnt = 0
       
        for tx,ty in vec:
            nx = x+tx
            ny = y +ty
            if nx > h-1 or ny > w-1:continue
            if field[nx][ny] == '#':
                cnt+=1
                next.append((nx,ny))
        if cnt%2 == 0:
            ok = False
            break
    stack = next
if not (x ==h-1 and y == w-1):ok = False
if ok :print('Possible')
else:print('Impossible')


h,w = map(int,input().split())
field = [input()for _ in range(h)]
vec = [(1,0),(0,1),(-1,0),(0,-1)]
stack = [(0,0)]
visited = [[0]*w for i in range(h)]
ok = True
while stack:
    next = []
    for x,y in stack:
        cnt = 0
       
        for tx,ty in vec:
            nx = x+tx
            ny = y +ty
            if nx > h-1 or ny > w-1 or nx <0 or ny < 0:continue
            if visited[nx][ny] :continue
            if (not visited[nx][ny]) and (x < nx or y < ny):
                ok = False
                break
            visited[nx][ny] = 1
            if field[nx][ny] == '#':
                cnt+=1
                next.append((nx,ny))
            
        if cnt == 2:
            ok = False
            break
    stack = next
if not (x ==h-1 and y == w-1):ok = False
if ok :print('Possible')
else:print('Impossible')


h,w = map(int,input().split())
f = [input()for _ in range(h)]
res = 0
for  i in range(h):
    res += f[i].count('#')
if res  == h+w-1:print('Possible')
else:print('Impossible')


Verdicts: Wrong Answer

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):
import sys
H,W=map(int,input().split())
listA=[list(input()) for i in range(H)]
start=[0,0]
while 1:
  if start==[H-1,W-1]:
    print("Possible")
    sys.exit()
  if start[1]==W-1 and start[0]!=H-1:
    print("Impossible")
    sys.exit()
  if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#":
    print("Impossible")
    sys.exit()
  if start[0]!=0 and start[1]!=0 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#" and listA[start[0]-1][start[1]]=="#":
    print("Impossible")
    sys.exit()
  if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#":
    start=[start[0]+1,start[1]]
    continue  
  if listA[start[0]][start[1]+1]=="#":
    start=[start[0],start[1]+1]    
  else:
    print("Impossible")

import sys
H,W=map(int,input().split())
listA=[list(input()) for i in range(H)]
start=[0,0]
while 1:
  if start==[H-1,W-1]:
    print("Possible")
    sys.exit()
  if start[1]==W-1 and start[0]!=H-1:
    print("Impossible")
    sys.exit()
  if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#":
    print("Impossible")
    sys.exit()
  if start[1]!=0 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#":
    print("Impossible")
    sys.exit()
  if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#":
    start=[start[0]+1,start[1]]
    continue  
  if listA[start[0]][start[1]+1]=="#":
    start=[start[0],start[1]+1]    
  else:
    print("Impossible")

import sys
H,W=map(int,input().split())
listA=[list(input()) for i in range(H)]
start=[0,0]
while 1:  
  if start[0]!=H-1 and start[1]!=W-1 and listA[start[0]+1][start[1]]=="#" and listA[start[0]][start[1]+1]=="#":
    print("Impossible")
    sys.exit()
  if start[0]!=0 and start[1]!=0 and listA[start[0]-1][start[1]]=="#" and listA[start[0]][start[1]-1]=="#":
    print("Impossible")
    sys.exit()
  if start==[H-1,W-1]:
    print("Possible")
    sys.exit()  
  if start[0]!=H-1 and listA[start[0]+1][start[1]]=="#":
    start=[start[0]+1,start[1]]
    continue  
  if start[1]!=W-1 and listA[start[0]][start[1]+1]=="#":
    start=[start[0],start[1]+1]    
  else:
    print("Impossible")

Verdicts: Runtime Error

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)]

sh, sw = 0, 0
gh, gw = H-1, W-1
move = [(1, 0), (0, 1)]

queue= [[0, 0]]

if grid[0][0] == ".":
    print("Impossible")
else:
    while sh != gh or sw != gw:
        sh, sw = queue.pop(0)
        cnt = 0
        for i, j in move:
            if sh+i >= H or sw+j >= W:
                continue
            if grid[sh+i][sw+j] == "#":
                if cnt:
                    print("Impossible")
                    exit()
                else:
                    cnt += 1
                    queue.append([sh+i, sw+j])
        if not queue:
            print("Impossible")
            exit()
    print("Possible")



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


Verdicts: Wrong Answer

Accepted