Skip to content

Commit

Permalink
Merge pull request #80 from AlgoLeadMe/22-seongwon030
Browse files Browse the repository at this point in the history
22-seongwon030
  • Loading branch information
seongwon030 authored Aug 6, 2024
2 parents bced723 + 4387fe2 commit 10b377e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions seongwon030/bfs/μ•ŒνŒŒλ²³.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
input = sys.stdin.readline

def bfs(original, x, y):
ans = 1
q = set([(x, y, k[y][x])])
while q:
x, y, alpha = q.pop()
ans = max(ans, len(alpha))
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < c and 0 <= ny < r and k[ny][nx] not in alpha:
q.add((nx, ny, alpha + original[ny][nx]))
return ans

r, c = map(int, input().split())
k = []
for _ in range(r):
k.append(list(input()))

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

print(bfs(k, 0, 0))

0 comments on commit 10b377e

Please sign in to comment.