Search

숫자 정사각형

Created
2021/09/27 09:40
문제 번호
1051
카테고리
구현
브루트포스

Memo

입력으로 받은 가로와 세로 중 더 작은 값이 최대로 서치할 수 있는 변의 길이가 됨 → KK
각 점에 대해 rowrowcolcol에 대해 1pointK1 ≤ point ≤ K의 범위로 정사각형을 만족하는지 확인
확인할 점들은 현재 위치를 기준으로 row+pointrow + point, col+pointcol + point로 확인할 수 있음

Code

제출 날짜

@9/26/2021

메모리

2020 KB

시간

0 ms
#include <iostream> #include <vector> std::vector<std::string> g_tile; int g_row; int g_col; int g_answer; void pre_setting(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); } void input_action(void) { std::cin >> g_row >> g_col; g_tile = std::vector<std::string>(g_row, std::string(g_col, '0')); for (auto& i : g_tile) for (auto& j : i) std::cin >> j; } void solution(void) { int side; side = std::min(g_row, g_col); for (int i = 0; i < g_row; ++i) { for (int j = 0; j < g_col; ++j) { for (int k = 0; k < side; ++k) { if (i + k < g_row && j + k < g_col) if (g_tile[i][j] == g_tile[i][j + k] && g_tile[i][j] == g_tile[i + k][j] && g_tile[i][j] == g_tile[i + k][j + k]) g_answer = std::max(g_answer, k); } } } } void output_action(void) { std::cout << (g_answer + 1) * (g_answer + 1); } int main(void) { pre_setting(); input_action(); solution(); output_action(); return (0); }
C++
복사