TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
#problem-c
n = int(input())
p = list(map(int, input().split()))
cnt = 0
min_p = p[0]
for i in range(n):
    if p[i]<=min_p:
        cnt += 1
        min_p = p[i]
    else:
print(cnt)


#problem-c
n = int(input())
p = list(map(int, input().split()))
cnt = 0
min_p = p[0]
for i in range(n):
    if p[i]=<min_p:
        cnt += 1
        min_p = p[i]
    else:
print(cnt)


#problem-c
n = int(input())
p = list(map(int, input().split()))
cnt = 0
min_p = p[0]
for i in range(n):
    if p[i]<=min_p:
        cnt += 1
        min_p = p[i]
print(cnt)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
ans = 1
c = a[0]
for i in range(1, n):
  if min(c,a[i])== a[i]:
    ans += 1
print(ans)

n = int(input())
p = list(map(int, input().split()))
b =1
for i in range(n):
  if p[i] ==min(p[0:i+1]):
    b += 1
print(b)
                

n = int(input())
a = list(map(int, input().split()))
ans = 1
c = a[0]
for i in range(1, n):
  if min(c,a[i])== a[i]:
    c = a[i]
    ans += 1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
P = input().split()
P = [int(p) for p in P]

ans = N
min_p = P[0]
for p in P[1:N]:
  if min_p > p:
    min_P = p
  else:
    ans -=1
  
  
print(ans)

N = int(input())
P = input().split()
P = [int(p) for p in P]

ans = N
min_p = P[0]
for p in P[1:N]:
  if min_p > p:
    min_p = p
  else:
    ans -=1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
P = [int(x) for x in input().split()]
count = 0
check = 0
for i in range(N):
    check = 0
    for j in range(i):
        if P[i] > P[j]:
            check = 1
            break
    if check == 0:
    count += 1

print(count)


N = int(input())
P = [int(x) for x in input().split()]
count = 0
check = 0
min = 10**9
for i in P:
    check = 0
    if min > i:
        min = i
    if i <= min:
        count += 1

print(count)


Verdicts: Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
n = int(input())
nn = [x for x in range(n)]
p = list(map(int,input().split()))
check = []
for i in nn:
    for j in range(0,i+1):
        if p[i] == n:
            continue
        else:
            if p[i] > p[j]:
                check.append(i)
                continue
print(n-len(set(check)))

n = int(input())
p = list(map(int,input().split()))
ans = 0
mini = n
for i in p:
    if i <= mini:
        ans += 1
        mini = i 
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
List = [int(x) for x in input().split()]

cnt = 0
min_num = List[0]
for i in List[1:]:
    if i < min_num:
        min_num = i
        cnt += 1
print(cnt)


N = int(input())
List = [int(x) for x in input().split()]

cnt = 0
min_num = List[0]

for i in List[1:]:
    if i < min_num:
        min_num = i
        cnt += 1
print(cnt)


N = int(input())
List = [int(x) for x in input().split()]

cnt = 1
min_num = List[0]

for i in List[1:]:
    if i < min_num:
        min_num = i
        cnt += 1
print(cnt)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
li = list(map(int,input().split()))

counter = 0

for i in range(0,N):
    if li[i+1]>li[i]:
        counter += 1
    else:
        pass
print(counter)

n = int(input())
l = list(map(int, input().split()))

total = 0
minl = l[0]

for i in l:
    if i <= minl:
        total += 1
        minl = i

print(total)


Verdicts: Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
import bisect
import numpy as np

def main():
    N = int(input())
    P = list(map(int, input().split()))


    ans = 1
    f = P[0]
    
    for i in range(1, N):
        f_o = P[i]
        if f >= f_o:
            ans+=1
            f = f_o
        
    return 0


if __name__ == '__main__':
    main()

import bisect
import numpy as np

def main():
    N = int(input())
    P = list(map(int, input().split()))


    ans = 1
    f = P[0]

    for i in range(1, N):
        f_o = P[i]
        if f >= f_o:
            ans+=1
            f = f_o
    print(ans)
    return 0


if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
P = list(map(int, input().split()))
a = P[0]
cnt = 1
for i in P:
    if a > P:
        a = P
        count += 1
print(count)


N = int(input())
P = list(map(int, input().split()))
a = P[0]
cnt = 1
for i in P:
    if a > i:
        a = i
        cnt += 1
print(cnt)




Verdicts: Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
m = min(A)
cnt = 0
for i in range(N):
  if A[N-1-i] == m:
    m = max(A[:N-1-i])
    cnt += 1
print(cnt)

N = int(input())
A = list(map(int, input().split()))
m = min(A)
cnt = 0
for i in range(N):
  if A[N-1-i] == m:
    m = min(A[:N-1-i])
    cnt += 1
print(cnt)

N = int(input())
A = list(map(int, input().split()))
m = N + 1
cnt = 0
for i in range(N):
  if m > A[i]:
    m = A[i]
    cnt += 1
print(cnt)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())

INF = 99999999

P = list(map(int, input().split()))

mins = [INF] * N

ans = 1
mins[0] = P[0]

for i in range(1,N):

    if (mins[i-1] > P[i]):
        ans += 1
        mins[i] = P[i]
#        print("i:" + str(i));
#        print(mins);
    else:
        mins[i] = mins[i-1]

N = int(input())

INF = 99999999

P = list(map(int, input().split()))

mins = [INF] * N

ans = 1
mins[0] = P[0]

for i in range(1,N):

    if (mins[i-1] > P[i]):
        ans += 1
        mins[i] = P[i]
#        print("i:" + str(i));
#        print(mins);
    else:
        mins[i] = mins[i-1]

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
n=int(input())
p=map(int,input().split())
for i in range(1,n):p[i]=min(p[i-1],p[i])
print(len(set(p)))


n,*p=map(int,open(0).read().split())
for i in range(1,n):p[i]=min(p[~-i],p[i])
print(len(set(p)))


Verdicts: Runtime Error

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
n = int(input())
p = list(input('').split())

sum = [i for i in range(1,n+1)]
sum = 0.5*1/6 * n *  (2 * n * n + 2 * n + 2 * n + 1) + 0.5 * 0.5 * n * n + 0.5 * n


max = 0
count = 0
for i in range(1,n):
    if int(p[i]) >= max:
        count += 1
    if max < int(p[i]):
        max = int(p[i])
print(int((count+1)/sum))

n = int(input())
p = list(input('').split())
print(p)

count = 0
count2 = 0
for i in range(1,n):
    count = 0
    for j in range(i):
        if int(p[j]) >= int(p[i]):
            count += 1
    if count == i:
        count2 += 1

print(count2 + 1)

n = int(input())
p = list(input('').split())

min = 10000000000
count = 0
for i in range(n):
    if min >= int(p[i]):
        count += 1
    if min >= int(p[i]):
        min = int(p[i])

print(count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = input()
Pn = input().split()
result = 0
last = Pn[0]  

for i in Pn:
    if int(last) >= int(i):
        print(i)
        result += 1
    last = int(i)

print(result)


N = input()
Pn = input().split()

result = 0
last = Pn[0]  

for i in Pn:
    if int(last) >= int(i):
        result += 1
        last = int(i)

print(result)


Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
P_list = [int(i) for i in input().split()]




#     pi = P_list[i]
#     is_match = True



#             is_match = False
#             break
    
#     if (is_match) :
#         cnt += 1

cnt = 1 
min_map = [P_list[0]]
min_value = P_list[0]
for i in range(1,len(P_list)) :
    min_value = min(min_value,P_list[i])
    min_map.append(min_value)

print(min_map)
for i in range(1,len(P_list)) :
    if (min_map[i] >= P_list[i]) :
        cnt += 1



print(cnt)

N = int(input())
P_list = [int(i) for i in input().split()]




#     pi = P_list[i]
#     is_match = True



#             is_match = False
#             break
    
#     if (is_match) :
#         cnt += 1

cnt = 1 
min_map = [P_list[0]]
min_value = P_list[0]
for i in range(1,len(P_list)) :
    min_value = min(min_value,P_list[i])
    min_map.append(min_value)

# print(min_map)
for i in range(1,len(P_list)) :
    if (min_map[i] >= P_list[i]) :
        cnt += 1



print(cnt)

Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
N = int(input())
P = []
counter = 0
input_string = input()
P = input_string.split()

for i in range(N):
    for j in range(N):
        print(N)
        print(P[i])
        if N == int(P[i]):
            counter = counter + 1
            if N != 1:
                N = N - 1
                break
            else: 
                break
        elif N < int(P[i]):
            break
        else:
            if N != 1:
                N = N - 1   

print(counter)


n = input()
N = int(n)
P = []
counter = 0
input_string = input()
P = input_string.split()

for i in range(int(N)):
    for j in range(N):
        if N == int(P[i]):
            counter = counter + 1
            if N != 1:
                N = N - 1
                break
            else: 
                break
        elif N < int(P[i]):
            break
        else:
            if N != 1:
                N = N - 1   

print(counter)


Verdicts: Wrong Answer

Accepted
Problem: Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition:    * For any integer j (1 \leq j \leq i), P_i \leq P_j.

Submission attempts (in order):
n=int(input())
p=list(map(int,input().split())

min=10000000000
ans=0
       
for i in p:
  if i <= min:
    ans+=1
    min=i
print(ans)


n=int(input()
p=list(map(int,input().split())

min=10000000000
ans=0
       
for i in p:
  if i <= min:
    ans+=1
    min=i
print(ans)

n=int(input())
p=list(map(int,input().split()))

min=10000000000
ans=0
       
for i in p:
  if i <= min:
    ans+=1
    min=i
print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import numpy as np
from collections import deque

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

maze = []
for h in range(H):
  s = input()
  maze.append(s)

def BFS(i,j):
  place = np.zeros((H,W))
  dist = 0
  queue = deque()
  queue.append((i,j,0))
  while queue:
    i,j,d = queue.popleft()
    if not place[i][j]:
      dist = max(dist,d)
      place[i][j] = 1
      for di,dj in [(1,0),(-1,0),(0,1),(0,-1)]:
        if (0 =< i+di and i+di < H and 0 =< j+dj and j+dj < W):
          if maze[i+di][j+dj] == '.' and place[i+di][j+dj] == 0:
            queue.append((i+di,j+dj,d+1))
  return dist

ans = 0
for h in range(H):
  for w in range(W):
    if maze[h][w] == '.':
      ans = max(ans,BFS(h,w))

print(ans)




import numpy as np
from collections import deque

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

maze = []
for h in range(H):
  s = input()
  maze.append(s)

def BFS(i,j):
  place = np.zeros((H,W))
  dist = 0
  queue = deque()
  queue.append((i,j,0))
  while queue:
    i,j,d = queue.popleft()
    if not place[i][j]:
      dist = max(dist,d)
      place[i][j] = 1
      for di,dj in [(1,0),(-1,0),(0,1),(0,-1)]:
        if (0 <= i+di and i+di < H and 0 <= j+dj and j+dj < W):
          if maze[i+di][j+dj] == '.' and place[i+di][j+dj] == 0:
            queue.append((i+di,j+dj,d+1))
  return dist

ans = 0
for h in range(H):
  for w in range(W):
    if maze[h][w] == '.':
      ans = max(ans,BFS(h,w))

print(ans)




Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

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

def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)
ans=0
for i in range(h):
    for j in range(w):
        if miti[i][j]=="#":continue
        dist=[[-1 for i in range(w)] for j in range(h)]
        dist[i][j]=0
        queue=deque([])
        bfs(i,j)
        print(dist)
        
        for s in range(h):
            for t in range(w):
                ans=max(ans,dist[s][t])
print(ans)

import sys
import math
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)

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

def bfs(x,y):
    for i,j in [[x+1,y],[x,y+1],[x-1,y],[x,y-1]]:
        if i<0 or h<=i or j<0 or w<=j :continue
        if dist[i][j] != -1:continue
        if miti[i][j]=="#":continue
        dist[i][j]=dist[x][y]+1
        queue.append([i,j])
    while queue:
        t,r=queue.popleft()
        bfs(t,r)
ans=0
for i in range(h):
    for j in range(w):
        if miti[i][j]=="#":continue
        dist=[[-1 for i in range(w)] for j in range(h)]
        dist[i][j]=0
        queue=deque([])
        bfs(i,j)
        
        
        for s in range(h):
            for t in range(w):
                ans=max(ans,dist[s][t])
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import queue

dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

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

ans = 0


for y in range(h):
    for x in range(w):
    
        i = 0
        move = [[-1] * w for _ in range(h)]
        print(x, y)
        
        if(maze[y][x] == '#'):
            continue

        
        q = queue.Queue()
        q.put([x, y])
        move[y][x] = 0

        while not q.empty():
            pos = q.get()
            for i in range(4):
                next = [pos[0] + dx[i], pos[1] + dy[i]]

                
                if(next[0] == w or next[1] == h or next[0] < 0 or next[1] < 0):
                    continue

                if(maze[next[1]][next[0]] == '.' and move[next[1]][next[0]] == -1):
                    move[next[1]][next[0]] = move[pos[1]][pos[0]] + 1
                    q.put(next)
        ans = max([ans] + [max(v) for v in move])

print(ans)



import queue

dx = (1, 0, -1, 0)
dy = (0, 1, 0, -1)

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

ans = 0


for y in range(h):
    for x in range(w):
    
        i = 0
        move = [[-1] * w for _ in range(h)]
        
        if(maze[y][x] == '#'):
            continue

        
        q = queue.Queue()
        q.put([x, y])
        move[y][x] = 0

        while not q.empty():
            pos = q.get()
            for i in range(4):
                next = [pos[0] + dx[i], pos[1] + dy[i]]

                
                if(next[0] == w or next[1] == h or next[0] < 0 or next[1] < 0):
                    continue

                if(maze[next[1]][next[0]] == '.' and move[next[1]][next[0]] == -1):
                    move[next[1]][next[0]] = move[pos[1]][pos[0]] + 1
                    q.put(next)
        ans = max([ans] + [max(v) for v in move])

print(ans)



Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import numpy as np
from collections import deque
 
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
 
dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
visited = np.zeros((h, w))
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#': continue
        q = deque()
        q.append((i, j, 0))
        visited[:, :] = 0
        while q:
            x, y, z = q.popleft()
            for dx, dy in dirr:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx, ny] and s[nx][ny] == '.':
                        q.append((nx, ny, z + 1))
                        if z + 1 > ans: ans = z
                        visited[x, y] = 1
print(ans)

from collections import deque
 
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
 
dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#': continue
        q = deque()
        q.append((i, j, 0))
        visited = [[False] * w for _ in range(h)]
        while q:
            x, y, z = q.popleft()
            for dx, dy in dirr:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx, ny] and s[nx][ny] == '.':
                        q.append((nx, ny, z + 1))
                        if z + 1 > ans: ans = z + 1
                        visited[nx][ny] = True
print(ans)


from collections import deque
 
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
 
dirr = ((1, 0), (0, 1), (-1, 0), (0, -1))
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#': continue
        q = deque()
        q.append((i, j, 0))
        visited = [[False] * w for _ in range(h)]
        visited[i][j] = True
        while q:
            x, y, z = q.popleft()
            for dx, dy in dirr:
                nx, ny = x + dx, y + dy
                if 0 <= nx < h and 0 <= ny < w:
                    if not visited[nx][ny] and s[nx][ny] == '.':
                        q.append((nx, ny, z + 1))
                        if z + 1 > ans: ans = z + 1
                        visited[nx][ny] = True
print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import math
import collections
import fractions
import itertools
import functools
import operator
import numpy as np

def solve():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    ans = 0
    can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    for x in range(h):
        for y in range(w):
            if maze[x][y] == "#":
                continue
            dist = [[0]*w for _ in range(h)]
            stack = collections.deque()
            stack.append([x,y])
            while stack:
                h2, w2 = stack.popleft()
                for i, j in can_move:
                    newh, neww = h+i, w+j
                    if newh < 0 or neww < 0 or newh >= h or neww >= w:
                        continue
                    elif maze[newh][neww] != "#" and dist[newh][neww] == 0:
                        dist[newh][neww] = dist[h2][w2]+1
                        stack.append([newh, neww])
            dist[x][y] = 0
            ans = max(ans, np.max(dist))
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

import math
import collections
import fractions
import itertools
import functools
import operator
import numpy as np

def solve():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    ans = 0
    can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    for x in range(h):
        for y in range(w):
            if maze[x][y] == "#":
                continue
            dist = [[0]*w for _ in range(h)]
            stack = collections.deque()
            stack.append([x,y])
            while stack:
                h2, w2 = stack.popleft()
                for i, j in can_move:
                    newh, neww = h2+i, w2+j
                    if newh < 0 or neww < 0 or newh >= h or neww >= w:
                        continue
                    elif maze[newh][neww] != "#" and dist[newh][neww] == 0:
                        dist[newh][neww] = dist[h2][w2]+1
                        stack.append([newh, neww])
            dist[x][y] = 0
            ans = max(ans, np.max(dist))
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
#!/usr/bin/env python
# coding: utf-8

# In[11]:


from collections import deque


# In[23]:


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


# In[24]:


def bfs(sx,sy):
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    d = [[-1]*W for _ in range(H)]
    q = deque([])
    q.append([sx,sy])
    d[sx][sy] = 0
    ans = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and d[nx][ny] == -1:
                q.append([nx,ny])
                d[nx][ny] = d[x][y] + 1
                ans = max(ans,d[nx][ny])
    return ans


# In[25]:


for sh in range(H):
    if "." in S[sh]:
        for sw in range(W):
            if S[sh][sw] == ".":
                ans = max(ans,bfs(sh,sw))
print(ans)


# In[ ]:






#!/usr/bin/env python
# coding: utf-8

# In[1]:


from collections import deque


# In[2]:


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


# In[3]:


def bfs(sx,sy):
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    d = [[-1]*W for _ in range(H)]
    q = deque([])
    q.append([sx,sy])
    d[sx][sy] = 0
    ans = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] != "#" and d[nx][ny] == -1:
                q.append([nx,ny])
                d[nx][ny] = d[x][y] + 1
                ans = max(ans,d[nx][ny])
    return ans


# In[5]:


ans = 0
for sh in range(H):
    if "." in S[sh]:
        for sw in range(W):
            if S[sh][sw] == ".":
                ans = max(ans,bfs(sh,sw))
print(ans)


# In[ ]:






Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from copy import deepcopy
from collections import deque

h,w=nii()
s=[list(input()) for i in range(h)]

def dfs(cs,i,j):
  que=deque()
  que.append([i,j])

  cs[i][j]='#'

  dist=[[-1 for a in range(w)] for b in range(h)]
  dist[i][j]=0

  while que:
    y,x=que.popleft()
    for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
      ny=y+dy
      nx=x+dx
      if 0<=ny<h and 0<=nx<w and cs[ny][nx]=='.':
        que.append([ny,nx])
        cs[ny][nx]='#'
        dist[ny][nx]=dist[y][x]+1

  t_ans=0
  for a in dist:
    t_ans=max(t_ans,max(a))

  return t_ans

ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      cs=deepcopy(s)
      dist=dfs(cs,i,j)
      ans=max(ans,dist)

print(ans

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from copy import deepcopy
from collections import deque

h,w=nii()
s=[list(input()) for i in range(h)]

def dfs(cs,i,j):
  que=deque()
  que.append([i,j])

  cs[i][j]='#'

  dist=[[-1 for a in range(w)] for b in range(h)]
  dist[i][j]=0

  while que:
    y,x=que.popleft()
    for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
      ny=y+dy
      nx=x+dx
      if 0<=ny<h and 0<=nx<w and cs[ny][nx]=='.':
        que.append([ny,nx])
        cs[ny][nx]='#'
        dist[ny][nx]=dist[y][x]+1

  t_ans=0
  for a in dist:
    t_ans=max(t_ans,max(a))

  return t_ans

ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      cs=deepcopy(s)
      dist=dfs(cs,i,j)
      ans=max(ans,dist)

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import sys
sys.setrecursionlimit(1000000)
from collections import deque


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

def bfs(sx,sy,gx,gy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[float('inf')]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==float('inf') and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j,k,l))
print(count)

import sys
sys.setrecursionlimit(1000000)
from collections import deque


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

def bfs(sx,sy):
    dx = [0,1,0,-1]
    dy = [1,0,-1,0]
    d = [[-1]*w for i in range(h)]
    q = deque()
    q.append((sx,sy))
    d[sx][sy] = 0
    while q:
        x,y = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if  0<= nx < h and 0 <= ny < w and d[nx][ny]==-1 and s[nx][ny]=='.':
                q.append((nx,ny))
                d[nx][ny] = d[x][y]+1
    return max([max(i) for i in d])

count = 0
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            count  = max(count, bfs(i,j))
print(count)

Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
n,m=map(int,input().split())
ac=0
ans=[True]*n
wa=[0]*n
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=="AC" and ans[p]:
        ans[p]=False
        ac+=1
    elif s=="WA" and ans[p]:
        wa[p]+=1

cnt=0
for i in range(n):
    if not ans[i]:
        cnt+=wa[i]

print(ac,cnt)

from collections import defaultdict
import heapq
import math

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

edges = defaultdict(list)
field = []

for _ in range(H):
    field.append(input())

weight = 1
for i in range(H):
    for j in range(W):
        if j + 1 < W and field[i][j] == '.' and field[i][j + 1] == '.':
            edges[W * i + j].append((W * i + j + 1, weight))
            edges[W * i + j + 1].append((W * i + j, weight))
        if i + 1 < H and field[i][j] == '.' and field[i + 1][j] == '.':
            edges[W * i + j].append((W * (i + 1) + j, weight))
            edges[W * (i + 1) + j].append((W * i + j, weight))


def dijkstra(s):
    que = []
    dist = [float('inf')] * (H * W)
    dist[s] = 0
    heapq.heappush(que, (0, s))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for i in range(len(edges[v])):
            e = edges[v][i]
            if dist[e[0]] > dist[v] + e[1]:
                dist[e[0]] = dist[v] + e[1]
                heapq.heappush(que, (dist[e[0]], e[0]))

    dist = [0 if d == float('inf') else d for d in dist]
    return dist


ans = 0
for i in range(H*W):
    ans = max(ans, max(dijkstra(i)))

print(ans)


Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import Queue
dx=[1,0,-1,0]
dy=[0,1,0,-1]
H,W=input().split()
S=[]
for h in range(H):
  S.append(input())

def bfs(s):
  dist = [[-1]*H for _ in range(W)]
  
  h,w = s
  dist[h][w]=0
  que = queue.Queue()
  que.put(s)
  
  while not(que.empty):
    h,w = que.get()
    for d in range(4):
      nh = h + dx[d]
      nw = w + dy[d]
      if nh<0 or H<=nh or nw<0 or W<=nw:
        continue
      if S[nh][nw]=="#":
        continue
      if dist[nh][nw]==-1:
        dist[nh][nw]=dist[h][w]+1
        que.put([nh,nw])
  return dist(h,w)

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w]==".":
      ans = max(ans,bfs([h,w]))
print(ans)
      

    
      

import queue
dx=[1,0,-1,0]
dy=[0,1,0,-1]
H,W=map(int,input().split())
S=[]
for h in range(H):
  S.append(input())

def bfs(s):
  dist = [[-1]*W for _ in range(H)]
  
  h,w = s
  dist[h][w]=0
  que = queue.Queue()
  que.put(s)
  
  while not(que.empty()):
    h,w = que.get()
    for d in range(4):
      nh = h + dx[d]
      nw = w + dy[d]
      if nh<0 or H<=nh or nw<0 or W<=nw:
        continue
      if S[nh][nw]=="#":
        continue
      if dist[nh][nw]==-1:
        dist[nh][nw]=dist[h][w]+1
        que.put([nh,nw])
  return dist[h][w]

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w]==".":
      ans = max(ans,bfs([h,w]))
print(ans)
      


Verdicts: Runtime Error

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
def main():
    from copy import deepcopy
    from collections import deque
    h, w = map(int, input().split())
    wall = ["#"] * (w + 2)
    maze = [wall]
    for _ in range(h):
        line = ["#"] + list(input()) + ["#"]
        maze.append(line)
    maze.append(wall)

    ans = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            m = deepcopy(maze)
            que = deque()
            que.append((i, j, 0))
            tmp = 0
            while que:
                (x, y, c) = que.popleft()
                if m[x][y] == "#":
                    continue
                if m[x][y] == ".":
                    m[x][y] = "#"
                tmp = max(tmp, c)

                for v, w in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                    que.appendleft((x + v, y + w, c + 1))

            ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()


from collections import deque
from copy import deepcopy


def bfs(maze, s):
    que = deque()
    que.append(s)
    nx = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    while que:
        x, y, c = que.popleft()
        if maze[x][y] != ".":
            continue
        maze[x][y] = c
        for u, v in nx:
            que.append((x + u, y + v, c + 1))
    ll = sum(maze, [])
    s = set(ll) - {"#"}

    return max(s)


def main():
    h, w = map(int, input().split())
    wall = ["#"] * (w + 2)
    maze = [wall]
    road = []
    for i in range(1, h + 1):
        line = ["#"] + list(input()) + ["#"]
        maze.append(line)
        for j, k in enumerate(line):
            if k == ".":
                road.append((i, j, 0))
    maze.append(wall)

    ans = 0
    for p in road:
        m = deepcopy(maze)
        ans = max(ans, bfs(m, p))
    print(ans)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

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


graph = []
for i in range(H):
    row = input()
    graph.append(list(row))

ans = 0
cost_max = 0
for i in range(H):
    for j in range(W):

        costs = []
        for i in range(H):
            costs.append([-1] * W)

        sy = i
        sx = j
        if graph[sy][sx] == "#":
            continue
        
        costs[sy][sx] = 0
        q = [[sy, sx]]
        
        di = [1, -1, 0, 0]
        dj = [0, 0, -1, 1]

        while len(q) != 0:
            y, x = q.pop(0)

            for k in range(4):
                t = y + di[k]
                u = x + dj[k]
                if t < 0 or u < 0 or t >= H or u >= W:
                    continue
                if graph[t][u] == '#':
                    continue
                if costs[t][u] != -1:
                    continue
                costs[t][u] = costs[y][x] + 1
                q.append([t, u])
        print(costs)
        ans = max(ans,max(max(costs)))
print(ans)

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


graph = [list(input()) for i in range(H)]

ans = 0
for i in range(H):
    for j in range(W):
        costs = []
        for l in range(H):
            costs.append([-1] * W)
        sy = i
        sx = j
        if graph[sy][sx] == "#":
            continue
        costs[sy][sx] = 0
        q = [[sy, sx]]
        
        di = [1, -1, 0, 0]
        dj = [0, 0, -1, 1]

        while len(q) != 0:
            y, x = q.pop(0)

            for k in range(4):
                t = y + di[k]
                u = x + dj[k]
                if not (0<=t<H and 0<=u<W):
                    continue
                if graph[t][u] == '#':
                    continue
                if costs[t][u] != -1:
                    continue
                costs[t][u] = costs[y][x] + 1
                q.append([t, u])
        ans = max(ans, max([max(d) for d in costs]))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns.  The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is `#`, and a "road" square if S_{ij} is `.`.  From a road square, you can move to a horizontally or vertically adjacent road square.  You cannot move out of the maze, move to a wall square, or move diagonally.  Takahashi will choose a starting square and a goal square, which can be any road squares, and give the maze to Aoki.  Aoki will then travel from the starting square to the goal square, in the minimum number of moves required.  In this situation, find the maximum possible number of moves Aoki has to make.

Submission attempts (in order):
import collections

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

def bfs(x0, y0):
    visited = [[0 for _ in range(w)] for _ in range(h)]
    deq = collections.deque()
    deq.append((x0, y0, -1))

    mx = 0
    while len(deq) > 0:
        x, y, d = deq.popleft()
        nd = d + 1
        visited[x][y] = 1
        mx = max(mx, nd)

        for dx, dy in [(-1, 0), (0, -1), (+1, 0), (0, +1)]:
            nx = x + dx
            ny = y + dy
            if not (0 <= nx < h) or not (0 <= ny < w):
                # bound check
                continue
            if smat[nx][ny] == '#':
                # cell attr check
                continue
            if visited[nx][ny] == 1:
                # already visited
                continue
            v = (nx, ny, nd)
            deq.append(v)
    
    return mx

if all(all(col == '.' for col in row) for row in smat):
    print(w * h)
else:
    mxall = 0
    for x0 in range(h):
        for y0 in range(w):
            if smat[x0][y0] == '.':
                mx = bfs(x0, y0)
                mxall = max(mxall, mx)
    print(mxall)


import collections

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

def bfs(x0, y0):
    visited = [[0 for _ in range(w)] for _ in range(h)]
    deq = collections.deque()
    deq.append((x0, y0, -1))

    mx = 0
    while len(deq) > 0:
        x, y, d = deq.popleft()
        nd = d + 1
        visited[x][y] = 1
        mx = max(mx, nd)

        for dx, dy in [(-1, 0), (0, -1), (+1, 0), (0, +1)]:
            nx = x + dx
            ny = y + dy
            if not (0 <= nx < h) or not (0 <= ny < w):
                # bound check
                continue
            if smat[nx][ny] == '#':
                # cell attr check
                continue
            if visited[nx][ny] == 1:
                # already visited
                continue
            v = (nx, ny, nd)
            deq.append(v)
    
    return mx

if all(all(col == '.' for col in row) for row in smat):
    print((w - 1) + (h - 1))
else:
    mxall = 0
    for x0 in range(h):
        for y0 in range(w):
            if smat[x0][y0] == '.':
                mx = bfs(x0, y0)
                mxall = max(mxall, mx)
    print(mxall)


Verdicts: Wrong Answer

Accepted