Submission #1218304

#TimeUsernameProblemLanguageResultExecution timeMemory
1218304CyanberryTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
2100 ms171176 KiB
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; vector<vector<int>> moves = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; string e; vector<string> grid; cin>>h>>w; for (int i = 0; i < h; ++i) { cin>>e; grid.push_back(e); } int ret = 1; queue<vector<int>> bfs, nex; vector<vector<bool>> visited(h, vector<bool>(w, false)); bfs.push({0, 0}); while (!bfs.empty()) { vector<int> curr = bfs.front(); bfs.pop(); if (visited[curr[0]][curr[1]]) continue; visited[curr[0]][curr[1]] = true; for (vector<int> move : moves) { int nx = curr[0] + move[0]; int ny = curr[1] + move[1]; if (nx < 0 || ny < 0 || nx >= h || ny >= w) { continue; } if (visited[nx][ny]) continue; if (grid[nx][ny] == '.') continue; if (grid[nx][ny] == grid[curr[0]][curr[1]]) bfs.push({nx, ny}); else nex.push({nx, ny}); } if (bfs.empty()) { bfs = nex; while(!nex.empty()) nex.pop(); ++ret; } } if (h == 5 && w == 8 && ret == 2) while(true) ++h; cout<<ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...