Submission #405233

#TimeUsernameProblemLanguageResultExecution timeMemory
405233rieyuwTracks in the Snow (BOI13_tracks)C++14
100 / 100
752 ms122748 KiB
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <stack> #include <unordered_set> #include <set> #include <map> #include <unordered_map> #include <iomanip> #include <random> #include <queue> //#include <fstream> /*#include <cstdio> #include <ctime>*/ #include <complex> using namespace std; /*Problem: */ void solve() { int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); vector <vector<int>> depth(n, vector<int>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; /*cout << "grid" << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << grid[i][j]; cout << endl; }*/ int x[] = {-1, 1, 0, 0 }; int y[] = { 0, 0, -1, 1 }; deque<pair<int, int>> deck; deck.push_front({ 0, 0 }); depth[0][0] = 1; pair<int, int> trace, neig; char ani; int ani_depth; int ans = -1; while (!deck.empty()) { trace = deck.front(); deck.pop_front(); ani = grid[trace.first][trace.second]; ani_depth = depth[trace.first][trace.second]; ans = max(ans, ani_depth); for (int i = 0; i < 4; i++) { neig.first = trace.first + x[i]; neig.second = trace.second + y[i]; if (neig.first < 0 || neig.first >= n || neig.second < 0 || neig.second >= m || depth[neig.first][neig.second] != 0 || grid[neig.first][neig.second] == '.') continue; if (grid[neig.first][neig.second] == ani) { depth[neig.first][neig.second] = ani_depth; deck.push_front(neig); } else { depth[neig.first][neig.second] = ani_depth + 1; deck.push_back(neig); } } } /*cout << "depths" << endl; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << depth[i][j]; cout << endl; } */ cout << ans << endl; } int main() { //freopen("revegetate.in", "r", stdin); //freopen("revegetate.out", "w", stdout); cin.tie(0); ios::sync_with_stdio(0); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...