forked from encrypted-def/BOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1025.cpp
42 lines (42 loc) · 890 Bytes
/
1025.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
char map[10][10];
int N, M;
bool isSquare(int x) {
int t = (int)sqrt(x);
for (int i = t - 2; i <= t + 2; i++)
if (i*i == x) return true;
return false;
}
bool isOutOfBounds(int x, int y) {
return x < 0 || x >= N || y < 0 || y >= M;
}
int main(void) {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++)
scanf("%s", map[i]);
int ans = -1;
for (int x = 0; x < N; x++) {
for (int y = 0; y < M; y++) {
for (int dx = -N; dx < N; dx++) {
for (int dy = -M; dy < M; dy++) {
int val = 0;
if (dx == 0 && dy == 0)
continue;
int curX = x;
int curY = y;
while (!isOutOfBounds(curX, curY)) {
val = 10 * val + (map[curX][curY]-'0');
if (isSquare(val))
ans = max(ans, val);
curX += dx;
curY += dy;
}
}
}
}
}
printf("%d", ans);
}