#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define itn int
#define sacnf scanf
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 1, inf = 1e9;
int find_sum(vector<vector<int>>& pref, int i, int l, int r)
{
if (l == 0) return pref[i][r];
return pref[i][r] - pref[i][l - 1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<vector<bool>> v(n, vector<bool>(m));
vector<vector<int>> pref(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
for (int j = 0; j < m; j++)
{
if (s[j] == '#') v[i][j] = 1;
if (j == 0) pref[i][j] = v[i][j];
else pref[i][j] = pref[i][j - 1] + v[i][j];
}
}
int ans = 0;
for (int i = 0; i < n - 2; i++)
{
for (int j = 1; j < m - 1; j++)
{
if (v[i][j])
{
if (v[i + 1][j]) continue;
if (!v[i + 1][j - 1] || !v[i + 1][j + 1]) continue;
int k = i + 1, l = j - 1, r = j + 1;
bool flag = 0;
while (k + 1 < n)
{
if (v[k + 1][l + 1] && v[k + 1][r - 1])
{
if (l + 1 == r - 1)
{
ans++;
break;
}
int sm = find_sum(pref, k + 1, l + 1, r - 1);
if (sm != 2) break;
flag = 1;
k++;
l++;
r--;
}
else
{
if (flag) break;
if (l == 0 || r == m - 1) break;
if (!v[k + 1][l - 1] || !v[k + 1][r + 1]) break;
int sm = find_sum(pref, k + 1, l - 1, r + 1);
if (sm != 2) break;
k++;
l--;
r++;
}
}
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
26 ms |
15488 KB |
Output is correct |
15 |
Correct |
28 ms |
15888 KB |
Output is correct |
16 |
Correct |
70 ms |
14752 KB |
Output is correct |
17 |
Correct |
29 ms |
14620 KB |
Output is correct |
18 |
Correct |
40 ms |
16680 KB |
Output is correct |
19 |
Correct |
24 ms |
14156 KB |
Output is correct |
20 |
Correct |
27 ms |
16476 KB |
Output is correct |
21 |
Correct |
23 ms |
14076 KB |
Output is correct |
22 |
Correct |
42 ms |
14944 KB |
Output is correct |
23 |
Correct |
35 ms |
14236 KB |
Output is correct |
24 |
Correct |
43 ms |
15324 KB |
Output is correct |
25 |
Correct |
23 ms |
14064 KB |
Output is correct |
26 |
Correct |
31 ms |
14544 KB |
Output is correct |