Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions suyeun84/202511/08 BOJ G5 제곱수 찾기.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
```java
import java.io.*;
import java.util.*;

public class Main {
public static int N, M;
public static int[][] map;
public static String S, T;
public static int result = -1;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());

map = new int[N][M];
for(int i=0;i<N;i++) {
String s = br.readLine();
for(int j=0;j<M;j++) {
map[i][j] = Integer.parseInt(String.valueOf(s.charAt(j)));
}
}

for(int i=0;i<N;i++) {
for(int j=0;j<M;j++) {
for(int di =-N; di<N;di++){
for(int dj = -M; dj<M;dj++) {

if(di == 0 && dj == 0) {
continue;
}

int nI = i;
int nJ = j;
int now = 0;
while( nI >= 0 && nI < N && nJ >= 0 && nJ < M) {
now *= 10;
now += map[nI][nJ];

int sqrt_check = (int) Math.sqrt( (double) now);
if( sqrt_check * sqrt_check == now) result = Math.max(result, now);

nI += di;
nJ += dj;
}
}
}
}
}
System.out.println(result);
}
}
```