没判一子吃多个联通块,被坑了呜呜呜。
显然可以 dfs
枚举所有白棋的联通块,过程中对于每个白棋查询上下左右空的地方,即算出气,记得去重。当气为 时统计联通块大小。
然后来到了大坑点,对于一个气为 的联通块,落子将它的气变为
后有可能会将另一个联通块的气也变成
,所以需要对于每个落点开个
map
,存出下这个点能提的子数量,这个不难,请读者自己实现 /xyx。
于是就做完了,代码如下:
#pragma G++ optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define rg register
#define il inline
#define TT(T, Args) template<typename T, typename... Args>
#define L(i, a, b) for (rg int i = (a); i <= (b); i++)
#define R(i, a, b) for (rg int i = (a); i >= (b); i--)
#define rep(i, a) for (rg auto i : a)
using namespace std;
namespace xyx{
il int rd(){
int f = 1, x = 0;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
TT(T, Args) il void rd(T &x){
int f = 1;
x = 0;
char ch = getchar();
while(ch < '0' || ch > '9'){
if (ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
x *= f;
}
TT(T, Args) il void rd(T &x, Args &...args){rd(x), rd(args...);}
TT(T, Args) il void rdArr(T *arr, int cnt){while(cnt--) rd(*arr), arr++;}
il void wt(int x){
if (x < 0){
putchar('-');
x = -x;
}
if (x > 9) wt(x / 10);
putchar(x % 10 + 48);
}
il void wtln(int x){wt(x), putchar('\n');}
il void wtsp(int x){wt(x), putchar(' ');}
il void swap(int &x, int &y){x ^= y ^= x ^= y;}
il int max(int x, int y){return (x > y ? x : y);}
il int min(int x, int y){return (x < y ? x : y);}
il void ckmax(int &x, int y){x = max(x, y);}
il void ckmin(int &x, int y){x = min(x, y);}
il void cksum(int &x, int y){x += y;}
TT(T, Args) il void ckmax(T &x, T y, Args &...args){ckmax(x, y), ckmax(x, args...);}
TT(T, Args) il void ckmin(T &x, T y, Args &...args){ckmin(x, y), ckmin(x, args...);}
TT(T, Args) il void cksum(T &x, T y, Args &...args){cksum(x, y), cksum(x, args...);}
}
using namespace xyx;
using namespace std;
const int N = 1e3 + 5, M = 21, p = 1e9 + 7, inf = 0x3f3f3f3f3f3f3f3f;
int n, ans, siz;
set<pair<int, int> > st;
map<pair<int, int>, int> mp;
char s[N][N];
bool vis[N][N];
il void init(){
}
il void clear(){
}
const int dx[] = {0, 0, 0, 1, -1};
const int dy[] = {0, 1, -1, 0, 0};
il void cal(int x, int y){
if (x > 1 && s[x - 1][y] == '.') st.insert({x - 1, y});
if (x < n && s[x + 1][y] == '.') st.insert({x + 1, y});
if (y > 1 && s[x][y - 1] == '.') st.insert({x, y - 1});
if (y < n && s[x][y + 1] == '.') st.insert({x, y + 1});
}
il void dfs(int x, int y){
vis[x][y] = 1, siz++, cal(x, y);
L(i, 1, 4){
int tx = x + dx[i], ty = y + dy[i];
if (tx < 1 || tx > n || ty < 1 || ty > n || s[tx][ty] != '*' || vis[tx][ty]) continue;
dfs(tx, ty);
}
}
il void work(){
n = rd();
L(i, 1, n){
L(j, 1, n){
cin >> s[i][j];
}
}
L(i, 1, n){
L(j, 1, n){
if (s[i][j] == '*' && !vis[i][j]){
st.clear(), siz = 0;
dfs(i, j);
if (st.size() == 1) mp[*st.begin()] += siz;
}
}
}
for (auto [k, v] : mp) ckmax(ans, v);
wt(ans);
}
signed main(){
// #define file 114514
#ifdef file
freopen("code.in", "r", stdin);
freopen("code.out", "w", stdout);
#endif
// init();
int t = 1;
// t = rd();
while(t--){
// clear();
work();
// if (t) puts("");
}
return 0;
}