제출 #379167

#제출 시각아이디문제언어결과실행 시간메모리
379167ruadhanTracks in the Snow (BOI13_tracks)C++14
0 / 100
2133 ms584876 KiB
#include <bits/stdc++.h> #define pi pair<int, int> using namespace std; const int MAXN = 505; char grid[MAXN][MAXN]; int dist[MAXN][MAXN]; queue<pi> q; int n, m, ans = 0; int main() { cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; // for (int i = 0; i < n; i++) // { // for (int j = 0; j < m; j++) // cout << grid[i][j]; // cout << endl; // } // cout << endl; dist[0][0] = 1; q.push({0, 0}); while (!q.empty()) { // for (int i = 0; i < n; i++) // { // for (int j = 0; j < m; j++) // cout << dist[i][j] << " "; // cout << endl; // } // cout << endl; int i = q.front().first, j = q.front().second; q.pop(); ans = max(ans, dist[i][j]); if (i + 1 < n) { if (grid[i + 1][j] == '.') { } else if (grid[i][j] == grid[i + 1][j]) { dist[i + 1][j] = min((dist[i + 1][j] == 0 ? INT_MAX : dist[i + 1][j]), dist[i][j]); q.push({i + 1, j}); } else if (grid[i][j] != grid[i + 1][j]) { dist[i + 1][j] = min((dist[i + 1][j] == 0 ? INT_MAX : dist[i + 1][j]), dist[i][j] + 1); q.push({i + 1, j}); } } if (j + 1 < m) { if (grid[i][j + 1] == '.') { } else if (grid[i][j] == grid[i][j + 1]) { dist[i][j + 1] = min((dist[i][j + 1] == 0 ? INT_MAX : dist[i][j + 1]), dist[i][j]); q.push({i, j + 1}); } else if (grid[i][j] != grid[i][j + 1]) { dist[i][j + 1] = min((dist[i][j + 1] == 0 ? INT_MAX : dist[i][j + 1]), dist[i][j] + 1); q.push({i, j + 1}); } } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...