File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ public static int N , M ;
7+ public static int [][] map;
8+ public static String S , T ;
9+ public static int result = - 1 ;
10+ public static void main (String [] args ) throws IOException {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
12+
13+ StringTokenizer st = new StringTokenizer (br. readLine());
14+ N = Integer . parseInt(st. nextToken());
15+ M = Integer . parseInt(st. nextToken());
16+
17+ map = new int [N ][M ];
18+ for (int i= 0 ;i< N ;i++ ) {
19+ String s = br. readLine();
20+ for (int j= 0 ;j< M ;j++ ) {
21+ map[i][j] = Integer . parseInt(String . valueOf(s. charAt(j)));
22+ }
23+ }
24+
25+ for (int i= 0 ;i< N ;i++ ) {
26+ for (int j= 0 ;j< M ;j++ ) {
27+ for (int di = - N ; di< N ;di++ ){
28+ for (int dj = - M ; dj< M ;dj++ ) {
29+
30+ if (di == 0 && dj == 0 ) {
31+ continue ;
32+ }
33+
34+ int nI = i;
35+ int nJ = j;
36+ int now = 0 ;
37+ while ( nI >= 0 && nI < N && nJ >= 0 && nJ < M ) {
38+ now *= 10 ;
39+ now += map[nI][nJ];
40+
41+ int sqrt_check = (int ) Math . sqrt( (double ) now);
42+ if ( sqrt_check * sqrt_check == now) result = Math . max(result, now);
43+
44+ nI += di;
45+ nJ += dj;
46+ }
47+ }
48+ }
49+ }
50+ }
51+ System . out. println(result);
52+ }
53+ }
54+ ```
You can’t perform that action at this time.
0 commit comments