Submission #652397

#TimeUsernameProblemLanguageResultExecution timeMemory
652397tmarcinkeviciusTracks in the Snow (BOI13_tracks)C++14
100 / 100
697 ms142940 KiB
#include<bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define f first #define s second const int MAX_W = 4005; int N, M; char L[MAX_W][MAX_W]; int dep[MAX_W][MAX_W]; bool vis[MAX_W][MAX_W]; pii Move[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int main () { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for (int i = 0; i <= N + 1; i++) { for (int j = 0; j < M + 1; j++) { if (i == 0 || j == 0 || i == N + 1 || j == M + 1) { L[i][j] = '.'; continue; } cin >> L[i][j]; } } /*for (int i = 0; i <= N + 1; i++) { for (int j = 0; j < M + 1; j++) { cout << L[i][j]; } cout << '\n'; }*/ //cout << '\n'; deque<pii> q; q.push_front({1, 1}); int ans = 1; dep[1][1] = 1; vis[1][1] = true; while (!q.empty()) { //cout << "size = " << q.size() << '\n'; pii pos = q.front(); //cout << "pos = {" << pos.f << ", " << pos.s << "}\n"; //cout << "val: " << L[pos.f][pos.s] << '\n'; q.pop_front(); pii newpos; for (int i = 0; i < 4; i++) { newpos = {pos.f + Move[i].f, pos.s + Move[i].s}; if (vis[newpos.f][newpos.s] || (L[newpos.f][newpos.s] != 'F' && L[newpos.f][newpos.s] != 'R')) continue; vis[newpos.f][newpos.s] = true; if (L[newpos.f][newpos.s] == L[pos.f][pos.s]) { dep[newpos.f][newpos.s] = dep[pos.f][pos.s]; q.push_front(newpos); } else { dep[newpos.f][newpos.s] = dep[pos.f][pos.s] + 1; ans = max(ans, dep[pos.f][pos.s] + 1); q.push_back(newpos); } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...