Submission #1187098

#TimeUsernameProblemLanguageResultExecution timeMemory
1187098vux2codeTracks in the Snow (BOI13_tracks)C++20
2.19 / 100
953 ms1033888 KiB
// Src : Vux2Code
/* Note :

*/

#include <bits/stdc++.h>
#define fi first
#define se second
#define pusb push_back
#define popb pop_back
#define pusf push_front
#define popf pop_front

using namespace std;

// template <typename T> void vout(T s){ cout << s << endl; exit(0);}

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

const ll maxN = 4e3 + 5, maxLog = 20, inf64 = 1e18, inf32 = 1e9, mod = 1e9 + 7;

void maxi (ll &x, ll y) {x = max (x, y);}
void mini (ll &x, ll y) {x = min (x, y);}

/* ---------HASHING-------- */
// const base = 31, mod2 = 1e9 + 9;

/* ---------BITMASK-------- */
// ll count (ll x) {return __builtin_popcountll (x);}
// ll fst (ll x) {return 63 - __builtin_clzll (x);}
// ll last (ll x) {return __builtin_ctzll (x);}
// bool bit (ll x, ll y) {return ((x >> y) & 1);}

pll adj [] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

ll t = 1;

ll n, m;
char a [maxN] [maxN];
bool ck [maxN] [maxN];
pair <bool, bool> rf;

bool out (pll x) {
    return x. fi < 1 || x. fi > n || x. se < 1 || x. se > m || a [x. fi] [x. se] == '.' || ck [x. fi] [x.se];
}

void dfs (pll x) {
    if (a [x. fi] [x. se] == 'R') rf. fi = 1;
    else if (a [x. fi] [x.se] == 'F') rf. se = 1;
    ck [x. fi] [x. se] = 1;
    for (pll i : adj) {
        pll nx = {x. fi + i. fi, x. se + i. se};
        if (out (nx)) continue;
        dfs (nx);
    }
}

void solve () {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= m; j ++) {
            cin >> a [i] [j];
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i ++) {
        for (int j = 1; j <= m; j ++) {
            if (!ck [i] [j]) {
                rf = {0, 0};
                dfs ({i, j});
                ans += (int) rf. fi + rf. se;
            }
        }
    }
    cout << ans;
}

int main () {
    ios::sync_with_stdio (0);
    cin.tie (0);
    cout.tie (0);
    // #define TASK "E:/Code/CP/task"
    // if (fopen (TASK".inp", "r")) {
    //     freopen (TASK".inp", "r", stdin);
    //     freopen (TASK".out", "w", stdout);
    // }
    //cin >> t;
    while (t--) solve ();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...