//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define all(x) (x.begin(), x.end());
#define uint unsigned int
#define pb push_back
using namespace std;
const ll N = 2e5+1, INF = 1e18 , inf = 1e9 , mod = 1e9+7;
int n, m, cnt = 0, mn = inf, mx = -inf, mxsum, mnsum;
char a[2002][2002];
bool used[2002][2002];
int di[4]{-1, 0, 1, 0};
int dj[4]{0, -1, 0, 1};
bool ok = 0;
void dfs(int vi, int vj){
used[vi][vj] = 1;
cnt++;
mx = max(mx, vi-vj);
mn = min(mn, vi-vj);
mxsum = max(mxsum, vi+vj);
mnsum = min(mnsum, vi+vj);
for(int i = 0; i < 4; i++){
int toi = vi+di[i], toj = vj+dj[i];
if(toi >= 1 && toi <= n && toj >= 1 && toj <= m){
if(!used[toi][toj] && a[toi][toj] == '.'){
dfs(toi, toj);
}
}
else{
ok = 1;
}
}
}
int main(){
// freopen("points.in", "r", stdin);
// freopen("points.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(used[i][j] || a[i][j] == '#') continue;
else{
cnt = 0;
mx = -inf;
mn = inf;
mxsum = -inf;
mnsum = inf;
ok = 0;
dfs(i, j);
if(mxsum-mnsum == mx-mn && (mxsum-mnsum)%2 == 0 && !ok){
int q = (mxsum-mnsum)/2+1;
if(2*q*q-2*q+1 == cnt) ans++;
}
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
720 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
1104 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
2 ms |
720 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
720 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
724 KB |
Output is correct |
12 |
Correct |
5 ms |
1104 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
327 ms |
240820 KB |
Output is correct |
15 |
Correct |
48 ms |
7628 KB |
Output is correct |
16 |
Correct |
128 ms |
11012 KB |
Output is correct |
17 |
Correct |
253 ms |
173604 KB |
Output is correct |
18 |
Correct |
67 ms |
11980 KB |
Output is correct |
19 |
Correct |
142 ms |
46248 KB |
Output is correct |
20 |
Correct |
189 ms |
47684 KB |
Output is correct |
21 |
Correct |
134 ms |
42832 KB |
Output is correct |
22 |
Correct |
114 ms |
19036 KB |
Output is correct |
23 |
Correct |
139 ms |
17220 KB |
Output is correct |
24 |
Correct |
197 ms |
19040 KB |
Output is correct |
25 |
Correct |
243 ms |
211280 KB |
Output is correct |
26 |
Correct |
114 ms |
10772 KB |
Output is correct |