Submission #534378

#TimeUsernameProblemLanguageResultExecution timeMemory
534378aadit_ambadkarTracks in the Snow (BOI13_tracks)C++11
0 / 100
2090 ms78804 KiB
/* This code belongs to Aadit Ambadkar Date: 2022-03-07 21:34:47 Problem: tis */ #include <bits/stdc++.h> using namespace::std; typedef long long ll; #define F0R(i, n) for (int i = 0; i < n; i++) #define R0F(i, n) for (int i = n-1; i >= 0; i--) #define FOR(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define fastio ios::sync_with_stdio(0); cin.tie(0) #define MOD 1000000007 #define FF first #define SS second int n, m; int board[4005][4005]; bool vis[4005][4005]; int main() { fastio; cin >> n >> m; F0R(i, n) { string s; cin >> s; F0R(j, m) { if (s[i]=='F') board[i][j]=1; else if (s[i]=='R') board[i][j]=2; else board[i][j]=0; vis[i][j]=false; } } priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq; pq.push({1, {0, 0}}); int ans = 0; while (!pq.empty()) { auto p = pq.top(); pq.pop(); int g = p.FF, u = p.SS.FF, v = p.SS.SS; if (vis[u][v]) continue; ans = max(ans, g); vis[u][v]=true; if (u < n-1 && !vis[u+1][v] && board[u+1][v]!=0) pq.push({g+((board[u][v]==board[u+1][v]) ? 0 : 1), {u+1, v}}); if (u > 0 && !vis[u-1][v] && board[u-1][v]!=0) pq.push({g+((board[u][v]==board[u-1][v]) ? 0 : 1), {u-1, v}}); if (v < m-1 && !vis[u][v+1] && board[u][v+1]!=0) pq.push({g+((board[u][v]==board[u][v+1]) ? 0 : 1), {u, v+1}}); if (v > 0 && !vis[u][v-1] && board[u][v-1]!=0) pq.push({g+((board[u][v]==board[u][v-1]) ? 0 : 1), {u, v-1}}); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...