-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00871.cpp
67 lines (53 loc) · 1.35 KB
/
00871.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<string> g;
ll dfs(ll x, ll y){
if(x < 0 || y < 0 || x >= g.size() || y >= g[0].size() || g[x][y] == '0'){
return 0;
}
ll sum = 1;
g[x][y] = '0';
ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
for(ll i = 0; i < 8; i++){
sum += dfs(x+dx[i], y+dy[i]);
}
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll t; cin >> t;
cin.ignore();
string str; getline(cin, str); // dummy
ll Max = 0;
ll cs = 0;
while(getline(cin, str)){
if(str == "" || cin.bad()){
for(ll i = 0; i < g.size(); i++){
for(ll j = 0; j < g[0].size(); j++){
if(g[i][j] == '1'){
Max = max(Max, dfs(i, j));
}
}
}
cout << Max << "\n\n";
Max = 0;
g.clear();
continue;
}
g.push_back(str);
}
for(ll i = 0; i < g.size(); i++){
for(ll j = 0; j < g[0].size(); j++){
if(g[i][j] == '1'){
Max = max(Max, dfs(i, j));
}
}
}
cout << Max << "\n";
return 0;
}