제출 #1153949

#제출 시각아이디문제언어결과실행 시간메모리
1153949justin271828Selotejp (COCI20_selotejp)C++20
0 / 110
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; #define ii pair<int, int> #define f first #define s second int main() { int n, m; cin >> n >> m; string str[n]; for (int i = 0; i < n; i++) cin >> str[i]; bool v[n][m]; memset(v, false, sizeof(v)); int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (str[i][j] == '#' && !v[i][j]) { ans++; queue<ii> q; q.push({i, j}); while (!q.empty()) { ii p = q.front(); v[p.f][p.s] = true; if (p.f != 0 && str[p.f-1][p.s] == '#' && !v[p.f-1][p.s]) q.push({p.f-1, p.s}); if (p.f + 1 != n && str[p.f+1][p.s] == '#' && !v[p.f+1][p.s]) q.push({p.f+1, p.s}); q.pop(); } } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (str[i][j] == '#' && !v[i][j]) { ans++; queue<ii> q; q.push({i, j}); while (!q.empty()) { ii p = q.front(); v[p.f][p.s] = true; if (p.s != 0 && str[p.f][p.s-1] == '#' && !v[p.f][p.s-1]) q.push({p.f, p.s-1}); if (p.s + 1 != n && str[p.f][p.s+1] == '#' && !v[p.f][p.s+1]) q.push({p.f, p.s+1}); q.pop(); } } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...