#include <bits/stdc++.h>
#define dbg(x) cerr << #x << " = " << x << "\n"
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie()
using namespace std;
using ll = long long;
int n, m;
char c[int(1e5) + 10][100];
bool mk[int(1e5) + 10][100];
int f(int l, int r) {
int res = 0;
queue <pair <int, int> > q;
for (int i = l; i <= r; ++i)
for (int j = 0; j < m; ++j)
mk[i][j] = 0;
for (int i = l; i <= r; ++i)
for (int j = 0; j < m; ++j) {
if (mk[i][j])
continue;
++res;
q.push(make_pair(i, j));
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int xx = -1; xx < 2; ++xx)
for (int yy = -1; yy < 2; ++yy)
if ((!xx || !yy) && (xx != yy)) {
int cx = x + xx;
int cy = y + yy;
if (cx >= l && cx <= r && cy >= 0 && cy < m && !mk[cx][cy]) {
mk[cx][cy] = 1;
q.push(make_pair(cx, cy));
}
}
}
}
return res;
}
int main() {
fast_io;
cin >> n >> m;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
cin >> c[i][j];
int ans = 0;
for (int i = 0; i < n; ++i)
for (int j = i; j <= n; ++j)
ans += f(i, j);
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6060 ms |
6068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
35 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |