제출 #683708

#제출 시각아이디문제언어결과실행 시간메모리
683708BEMWATracks in the Snow (BOI13_tracks)C++17
0 / 100
748 ms47344 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t = 1; //cin >> t; while(t--){ int n, m; cin >> n >> m; bool vis[n][m]; char grid[n][m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> grid[i][j]; vis[i][j] = false; } } int ans = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(vis[i][j])continue; if(grid[i][j] == '.')continue; ans++; queue<pair<int,int>> q; q.push({i, j}); vis[i][j] = true; while(!q.empty()){ pair<int,int> cur = q.front(); q.pop(); for(int k = 0; k < 4; k++){ int nx = dx[k] + cur.first; int ny = dy[k] + cur.second; if(!(nx >= 0 and nx < n and ny >= 0 and ny < m))continue; if(vis[nx][ny])continue; if(grid[nx][ny] != grid[cur.first][cur.second])continue; vis[nx][ny] = true; q.push({nx, ny}); } } } } cout << ans / 2 << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...