From 5748de069c3798beef0a042841d011429b604543 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sun, 27 Jul 2025 23:51:41 +0900 Subject: [PATCH] =?UTF-8?q?[20250727]=20BOJ=20/=20G5=20/=20=EC=A0=9C?= =?UTF-8?q?=EA=B3=B1=EC=88=98=20=EC=B0=BE=EA=B8=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...61\354\210\230\354\260\276\352\270\260.md" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "Seol-JY/202507/27 BOJ G5 \354\240\234\352\263\261\354\210\230\354\260\276\352\270\260.md" diff --git "a/Seol-JY/202507/27 BOJ G5 \354\240\234\352\263\261\354\210\230\354\260\276\352\270\260.md" "b/Seol-JY/202507/27 BOJ G5 \354\240\234\352\263\261\354\210\230\354\260\276\352\270\260.md" new file mode 100644 index 00000000..ca3f5ac1 --- /dev/null +++ "b/Seol-JY/202507/27 BOJ G5 \354\240\234\352\263\261\354\210\230\354\260\276\352\270\260.md" @@ -0,0 +1,65 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; + +public class Main { + static int N, M; + static int[][] board; + static int maxSqrt = -1; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String[] sizes = br.readLine().split(" "); + N = Integer.parseInt(sizes[0]); + M = Integer.parseInt(sizes[1]); + + board = new int[N][M]; + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < M; j++) { + board[i][j] = line.charAt(j) - '0'; + } + } + + for (int row = 0; row < N; row++) { + for (int col = 0; col < M; col++) { + for (int dr = -N; dr <= N; dr++) { + for (int dc = -M; dc <= M; dc++) { + if (dr == 0 && dc == 0) continue; + + int r = row; + int c = col; + StringBuilder sb = new StringBuilder(); + + while (r >= 0 && r < N && c >= 0 && c < M) { + sb.append(board[r][c]); + long num = Long.parseLong(sb.toString()); + + if (isPerfectSquare(num)) { + maxSqrt = Math.max(maxSqrt, (int) num); + if (maxSqrt >= 31622 * 31622) { + System.out.println(maxSqrt); + return; + } + } + + r += dr; + c += dc; + } + } + } + } + } + + System.out.println(maxSqrt); + } + + static boolean isPerfectSquare(long num) { + long sqrt = (long) Math.sqrt(num); + return sqrt * sqrt == num; + } +} + +```