제출 #689080

#제출 시각아이디문제언어결과실행 시간메모리
689080Anonymous_GuysTracks in the Snow (BOI13_tracks)C++17
65.42 / 100
813 ms125908 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ii pair<int, int> const int mxN = 5e3; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int n, m; string s[mxN]; int ans[mxN][mxN]; bool check(int x, int y) { return (x >=0 && x < n && y >= 0 && y < n && s[x][y] != '.'); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> s[i]; deque<ii> dq; dq.pb({0, 0}); ans[0][0] = 1; int kq =0 ; while(dq.size()) { ii it = dq.front(); dq.pop_front(); kq = max(kq, ans[it.first][it.second]); for (int i = 0; i < 4; ++i) { int x = it.first + dx[i]; int y = it.second + dy[i]; if (check(x, y) && ans[x][y] == 0) { if (s[x][y] == s[it.first][it.second]) { ans[x][y] = ans[it.first][it.second]; dq.push_front({x, y}); } else { ans[x][y] = ans[it.first][it.second] + 1; dq.push_back({x, y}); } } } } cout << kq; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...