Submission #438473

#TimeUsernameProblemLanguageResultExecution timeMemory
438473zeyuTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
1241 ms123084 KiB
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int main(){ int n, m; cin >> n >> m; vector<string> a(n); for (int i = 0; i < n; i ++) cin >> a[i]; char cur = a[0][0]; int graph[n][m]; for (int i = 0; i < n; i ++){ for (int j = 0; j < m; j ++){ if (a[i][j] == cur) graph[i][j] = 1; else if (a[i][j] == '.') graph[i][j] = 0; else graph[i][j] = 2; } } int ans = 1; bool add = false; for (int i = 0; i < n; i ++) for (int j = 0; j < m; j ++) if (graph[i][j] == 2) add = true; if (add) ans ++; add = false; bool vis[n][m]; memset(vis, false, sizeof(vis)); vis[0][0] = true; queue<pair<int, int> > que; que.push(make_pair(0, 0)); while(! que.empty()){ pair<int, int> p = que.front(); que.pop(); for (int i = 0; i < 4; i ++){ int x = p.first + dx[i]; int y = p.second + dy[i]; if (x >= 0 && x < n && y >= 0 && y < m && ! vis[x][y]){ vis[x][y] = true; que.push(make_pair(x, y)); } } } for (int i = 0; i < n; i ++){ for (int j = 0; j < m; j ++){ if (graph[i][j] == 1 && ! vis[i][j]) { add = true; } } } if (add) ans ++; cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...