단순한 완전탐색 문제이다.
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 | #include <bits/stdc++.h> using namespace std; int n, m, maxv=0; int arr[50][50]; void dfs(int x, int y, int depth) { int nx = x + depth; int ny = y + depth; if (nx < n && ny < m) { if (arr[x][y] == arr[nx][y] && arr[x][y] == arr[x][ny] && arr[x][y] == arr[nx][ny]) { maxv = max(maxv, (depth + 1)*(depth + 1)); } dfs(x, y, depth + 1); } else return; } string s; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s; for (int j = 0; j < m; j++) arr[i][j] = s[j] - '0'; } for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) dfs(i, j, 0); cout << maxv; } | cs |
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 10825 : 국영수 (0) | 2019.01.04 |
---|---|
[BOJ] 10812 : 바구니 순서 바꾸기 (0) | 2019.01.03 |
[BOJ] 1107 : 리모컨 (0) | 2019.01.03 |
[BOJ] 1267 : 핸드폰 요금 (0) | 2019.01.03 |
[BOJ] 10816 : 숫자 카드 2 (0) | 2019.01.03 |