fork download
  1. import sys
  2.  
  3. n, m = map(int,sys.stdin.readline().split())
  4. board = [list(map(str,sys.stdin.readline().strip())) for _ in range(n)]
  5.  
  6. cnt = result = 1
  7. col = row = 0
  8.  
  9. while True:
  10. if cnt == n or cnt == m: #조사하는 사각형의 크기가 직사각형보다 크다면 종료
  11. break
  12. for i in range(n-cnt): #열: ex)cnt = 0이면 0-1 확인
  13. for j in range(m-cnt): #행: ex)cnt =0이면 0-1 확인
  14. #각 꼭지점이 같은 경우 result = cnt + 1
  15. #cnt 0은 총 1칸인 경우, cnt = 1은 총 4칸인 경우이므로 cnt + 1
  16. if board[i][j] == board[i][cnt+j] and board[i+cnt][j] == board[i+cnt][cnt+j]:
  17. result = cnt + 1
  18. cnt+=1
  19. print((result)**2)
Success #stdin #stdout 0.04s 9396KB
stdin
2 2
11
22
stdout
4