Submission #1166420

#TimeUsernameProblemLanguageResultExecution timeMemory
1166420sunflowerEmacs (COCI20_emacs)C++17
50 / 50
0 ms400 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define SZ(x) ((int) (x).size()) #define ALL(a) (a).begin(), (a).end() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) #define debug(x) cerr << "[" << #x << " = " << (x) << "]" << endl #define left __left #define right __right #define prev __prev #define fi first #define se second template <class X, class Y> bool maximize(X &x, Y y) { if (x < y) return x = y, true; else return false; } template <class X, class Y> bool minimize(X &x, Y y) { if (x > y) return x = y, true; else return false; } int numRow, numCol; const int dx[] = {-1, 0, 0, 1}; const int dy[] = {0, -1, 1, 0}; #define MAX_N 102 char a[MAX_N + 2][MAX_N + 2]; bool vis[MAX_N + 2][MAX_N + 2]; bool inside(int x, int y) { return (x >= 1 && x <= numRow && y >= 1 && y <= numCol); } void dfs(int u, int v) { vis[u][v] = true; FOR(i, 0, 3) { int nx = u + dx[i], ny = v + dy[i]; if (inside(nx, ny) && !vis[nx][ny] && a[nx][ny] == '*') dfs(nx, ny); } } int main() { ios_base::sync_with_stdio(false);cin.tie(nullptr); cin >> numRow >> numCol; FOR(i, 1, numRow) FOR(j, 1, numCol) cin >> a[i][j]; int ans = 0; FOR(i, 1, numRow) FOR(j, 1, numCol) if (a[i][j] == '*' && !vis[i][j]) dfs(i, j), ++ans; cout << ans; return 0; } /* Discipline - Calm */
#Verdict Execution timeMemoryGrader output
Fetching results...