Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <bits/stdc++.h>
using namespace std;

int row, col;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
vector<int> v;
vector<vector<bool>> visited;

void func(vector<vector<int>>& land, int x, int y)
{
queue<pair<int, int>> Q;

Q.push({x, y});
visited[x][y] = true;

int cnt = 0;
int ymin = y, ymax = y;

while(!Q.empty())
{
pair<int, int> cur = Q.front();
Q.pop();
cnt++;

// YMIN, YMAX 계산
if(cur.second < ymin) ymin = cur.second;
if(cur.second > ymax) ymax = cur.second;

for(int i = 0; i < 4; i++)
{
int nx = cur.first + dx[i];
int ny = cur.second + dy[i];

if(nx < 0 || ny < 0 || nx >= col || ny >= row) continue;
if(land[nx][ny] == 0 || visited[nx][ny]) continue;

visited[nx][ny] = true;
Q.push({nx, ny});
}
}

// YMINκ³Ό YMAX λ‚΄μ—μ„œ 크기 λˆ„μ 
for(int i = ymin; i <= ymax; i++)
{
v[i] += cnt;
}
}

int solution(vector<vector<int>> land) {
int ans = 0;
row = land[0].size();
col = land.size();
visited.resize(col,vector<bool>(row,false));
v.resize(row,false);

for(int i = 0; i < col; i++)
{
for(int j = 0; j < row; j++)
{
if(land[i][j] == 1 && visited[i][j] == false)
{
func(land, i, j);
}
}
}

// μ΅œλŒ€κ°’ 계산
for(int i = 0; i < row; i++)
{
ans = max(v[i], ans);
}

return ans;
}
1 change: 1 addition & 0 deletions hyeokbini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
| 19μ°¨μ‹œ | 2025.08.10 | 브루트포슀 | [리λͺ¨μ»¨](https://www.acmicpc.net/problem/1107)|[#19](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/68)|
| 20μ°¨μ‹œ | 2025.08.14 | 완전탐색,DFS | [λͺ¨μŒμ‚¬μ „](https://school.programmers.co.kr/learn/courses/30/lessons/84512)|[#20](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/72)|
| 21μ°¨μ‹œ | 2025.08.19 | 브루트포슀 | [제곱수 μ°ΎκΈ°](https://www.acmicpc.net/problem/1025)|[#21](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/76)|
| 24μ°¨μ‹œ | 2025.09.03 | BFS, κ΅¬ν˜„ | [μ„μœ  μ‹œμΆ”](https://school.programmers.co.kr/learn/courses/30/lessons/250136)|[#24](https://github.com/AlgoLeadMe/AlgoLeadMe-15/pull/83)|