Submission #333446

#TimeUsernameProblemLanguageResultExecution timeMemory
333446luanaamorimTracks in the Snow (BOI13_tracks)C++14
2.19 / 100
2095 ms142556 KiB
#include <iostream> #include <queue> using namespace std; char tab[4002][4002]; int n, m, f, r, ans, passou[4002][4002], passou2[4002][4002]; queue<pair<int, int> > fila; void bfs1(int a, int b) { fila.push(make_pair(a, b)); while (!fila.empty()) { int a = fila.front().first, b = fila.front().second; fila.pop(); if (a < 1 || b < 1 || a > n || b > m) continue; if (tab[a][b] != 'F' || passou[a][b]) continue; passou[a][b] = 1; fila.push(make_pair(a + 1, b)); fila.push(make_pair(a - 1, b)); fila.push(make_pair(a, b + 1)); fila.push(make_pair(a, b - 1)); } } void bfs2(int a, int b) { fila.push(make_pair(a, b)); while (!fila.empty()) { int a = fila.front().first, b = fila.front().second; fila.pop(); if (a < 1 || b < 1 || a > n || b > m) continue; if (tab[a][b] == '.' || passou2[a][b]) continue; passou2[a][b] = 1; fila.push(make_pair(a + 1, b)); fila.push(make_pair(a - 1, b)); fila.push(make_pair(a, b + 1)); fila.push(make_pair(a, b - 1)); } } int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> tab[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (tab[i][j] == 'F' && !passou[i][j]) bfs1(i, j), ans++; if (tab[i][j] == 'R' && !passou2[i][j]) bfs2(i, j), ans++; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...