Submission #683709

#TimeUsernameProblemLanguageResultExecution timeMemory
683709BEMWATracks in the Snow (BOI13_tracks)C++17
2.19 / 100
882 ms33600 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; set<char> S; queue<pair<int,int>> q; q.push({i, j}); vis[i][j] = true; S.insert(grid[i][j]); 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] == '.')continue; vis[nx][ny] = true; S.insert(grid[nx][ny]); q.push({nx, ny}); } } ans += S.size(); } } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...