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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string.h>
typedef struct {
int x;
int y;
}movepos;
int main(int argc, char* argv[]) {
int n, m;
char** map;
int** dp;
int answer=0;
movepos move[3] = { {-1,0},{-1,-1},{0,-1} };
scanf("%d %d", &n, &m);
map = new char*[n];
dp = new int* [n];
for (int i = 0; i < n; i++) {
map[i] = new char[m+1];
dp[i] = new int[m];
scanf("%s", map[i]);
memset(dp[i], 0, sizeof(int) * m);
}
for (int x = 0; x < n; x++) {
for (int y = 0; y < m; y++) {
if (map[x][y] == '0') {
dp[x][y] = 0;
continue;
}
int min;
int posx, posy;
bool one=false;
bool end=false;
for (int i = 0; i < 3; i++) {
posx = x + move[i].x;
posy = y + move[i].y;
if (posx < 0 || posy < 0 || dp[posx][posy] == 0) {
dp[x][y] = 1;
end = true;
break;
}
else if (dp[posx][posy] == 1) {
one = true;
continue;
}
if (i == 0) {
min = dp[posx][posy];
}
else if(min>dp[posx][posy]) {
min = dp[posx][posy];
}
}
if (end == false) {
if (one) {
dp[x][y] = 2;
}
else{
dp[x][y] = min + 1;
}
}
if (dp[x][y] > answer)
answer = dp[x][y];
}
}
printf("%d", answer*answer);
for (int i = 0; i < n; i++) {
delete[] map[i];
delete[] dp[i];
}
delete[] map;
delete[] dp;
return 0;
}
|
'기타 코딩 > PS' 카테고리의 다른 글
[백준] 구간 합 구하기 - 2042번 (0) | 2024.02.12 |
---|---|
[백준] 숫자 카드 - 10815번 (0) | 2024.02.12 |
[백준] 행렬 곱셈 순서 - 11049번 (0) | 2020.10.20 |
[백준] 테트로미노 - 14500번 (0) | 2020.10.20 |
[백준] 뱀 - 3190번 (0) | 2020.10.20 |