Submission #847751

#TimeUsernameProblemLanguageResultExecution timeMemory
847751AdishTracks in the Snow (BOI13_tracks)C++14
91.25 / 100
1416 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; const int N = 40001; int ans = 0; vector<vector<bool>> vis(N, vector<bool>(N, false)); void bfs(vector<string>&s, int n, int m, queue<pair<int, int>>&q){ ans++; queue<pair<int, int>>altr_q; while(!q.empty()){ pair<int, int>tp = q.front(); q.pop(); vector<int> dx = {-1, 0, 1, 0}; vector<int> dy = {0, 1, 0, -1}; for(int i = 0; i < 4; i++){ int x = tp.first + dx[i]; int y = tp.second + dy[i]; if(x >= 0 and x < n and y >=0 and y < m){ if(s[x][y] == '.' or vis[x][y]){ continue; } vis[x][y] = true; if(s[x][y] == s[tp.first][tp.second]){ q.push({x, y}); } else{ altr_q.push({x, y}); } } } } if(!altr_q.empty()){ bfs(s, n, m, altr_q); } } int main(){ int h, w; cin >> h >> w; vector<string>s(h); for(int i = 0; i < h; i++){ cin >> s[i]; } queue<pair<int, int>>q; q.push({0, 0}); vis[0][0] = true; bfs(s, h, w, q); cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...