Submission

Status:

[PPPPPPPPPPPPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: spiwips

Problemset: เกาะที่ใหญ่ที่สุด

Language: cpp

Time: 0.006 second

Submitted On: 2025-12-13 22:15:39

#include<bits/stdc++.h>

using namespace std;

int n,m;
int dir1[4] = {0,0,-1,1},dir2[4] = {-1,1,0,0};
char mp[175][175];
int vs[175][175];
int main() {

	queue<pair<int,int>> note;
	cin>>n>>m;
	//input stuff
	for(int i = 0 ; i < n; i ++)
	{
		for(int j = 0; j <m ; j++)
		{
			cin>>mp[i][j];
		}
	}


	//loop stuff
	int max_size = 0;
	
	pair<int,int> curr;
	for(int i = 0 ; i < n; i ++)
	{
		for(int j = 0; j <m ; j++)
		{
			//actual stuff
			if(vs[i][j] == 1||mp[i][j] == '0') {
				continue;
			}
            int counter = 1;
			note.push({i,j});
			vs[i][j] = 1;
			while(note.size()>0)
			{
				//go to close islands?

				curr = note.front();
				note.pop();
				for(int l = 0; l < 4; l++) {
					int new_i = curr.first+dir1[l];
					int new_j = curr.second+dir2[l];
					//cout<<mp[new_i][new_j]<<'\n';
					//island check
					if(mp[new_i][new_j] == '1' && vs[new_i][new_j] == 0) {
						////cout<<counter<<'\n';
						vs[new_i][new_j] = 1;
						note.push({new_i,new_j});
						counter++;
						//cout<<"yay";

					}
					//end check
				}

			}
			//end of actual stuff
			if(counter>max_size) {
				max_size = counter;
			}
		}
	}
	cout<<max_size;
}