Submission #891706

# Submission time Handle Problem Language Result Execution time Memory
891706 2023-12-23T17:09:00 Z ind1v Emacs (COCI20_emacs) C++11
50 / 50
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

const int N = 102;
const int dI[4] = {0, 0, -1, 1};
const int dJ[4] = {1, -1, 0, 0};

bool a[N][N], z[N][N];
int n, m, c;
string s;

bool check(int x, int y) {
  return (1 <= x && x <= n && 1 <= y && y <= m);
}

void ff(int x, int y) {
  if (!check(x, y)) return;
  if (z[x][y] == 1 || a[x][y] == 0) return;
  z[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    ff(x + dI[i], y + dJ[i]);
  }
}

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    for (int j = 1; j <= m; ++j) {
      a[i][j] = (s[j - 1] == '*');
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i][j] == 1 && z[i][j] == 0) {
        ff(i, j);
        ++c;
      }
    }
  }
  cout << c;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct