Submission #892532

#TimeUsernameProblemLanguageResultExecution timeMemory
892532vaneaTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
1053 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 4e3+10; char matrix[mxN][mxN]; bool vis[mxN][mxN]; int n, m; vector<int> xy = {1, 0, -1, 0}, yx = {0, 1, 0, -1}; int add = 1; void dfs(int x, int y) { char c = matrix[x][y]; vis[x][y] = true; for(int i = 0; i < 4; i++) { int a = x + xy[i], b = y + yx[i]; if(a >= 0 && a < n && b >= 0 && b < m && !vis[a][b]) { if(matrix[a][b] == c){ dfs(a, b); } if(matrix[a][b] != c && matrix[a][b] != '.') { add = 2; dfs(a, b); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { cin >> matrix[i][j]; } } int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(matrix[i][j] != '.' && !vis[i][j]) { dfs(i, j); ans += add; add = 1; } } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...