Submission #892859

#TimeUsernameProblemLanguageResultExecution timeMemory
892859stdfloatTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
1300 ms1036632 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int n, m, ans;

bool tr1, tr2;

vector<string> a;

vector<vector<bool>> vis;

bool chk(int x, int y) {
    return 0 <= min(x, y) && x < n && y < m && !vis[x][y];
}

void dfs(int x, int y) {
    if (vis[x][y]) return;
    vis[x][y] = true;

    if (a[x][y] == 'R') {
        ans += tr1; tr1 = false;
    }
    else {
        ans += tr2; tr2 = false;
    }

    if (chk(x - 1, y)) dfs(x - 1, y);
    if (chk(x + 1, y)) dfs(x + 1, y);
    if (chk(x, y - 1)) dfs(x, y - 1);
    if (chk(x, y + 1)) dfs(x, y + 1);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n >> m;

    a.assign(n, "");
    for (auto &i : a) cin >> i;

    vis.assign(n, vector<bool>(m, false));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '.') continue;

            tr1 = tr2 = true;
            dfs(i, j);
        }
    }

    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...