제출 #1251681

#제출 시각아이디문제언어결과실행 시간메모리
1251681kunzaZa183Tracks in the Snow (BOI13_tracks)C++20
97.81 / 100
885 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; const int mn = 4000; int vvi[mn][mn]; char vs[mn][mn + 1]; int n, m; int ct = 0; vector<pair<int, int>> newones, new2; int nx, ny; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; void flood(int x, int y) { if (vvi[x][y] != 0) return; vvi[x][y] = ct; for (int i = 0; i < 4; i++) { nx = x + dx[i], ny = y + dy[i]; if (nx >= 0 && nx < n && ny >= 0 && ny < m) { if (vvi[x][y] != 0 && vs[nx][ny] != '.') { if (vs[nx][ny] == vs[x][y]) flood(nx, ny); else { new2.push_back({nx, ny}); } } } } }; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < n; i++) cin >> vs[i]; newones.push_back({0, 0}); while (!newones.empty()) { ct++; for (auto [x, y] : newones) { flood(x, y); } new2.swap(newones); new2.clear(); } int maxi = 0; for (auto &a : vvi) for (auto b : a) maxi = max(maxi, b); cout << maxi << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...