| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|
| 1102487 |  | qrn | Zoo (COCI19_zoo) | C++14 |  | 384 ms | 138312 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
template<class ISqr, class T>
ISqr& operator>>(ISqr& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
#define SPEED                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define fi first
#define se second
 
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long
vector<vector<vector<int>>> v;
int bfs(int n, int st){
    vector<int> di(n, 1000000000);
    deque<int> q;
    di[st] = 0;
    q.push_back(st);
    while (!q.empty()){
        int x = q.front();
        q.pop_front();
        for (auto el : v[x]){
            if (di[el[0]] > di[x] + el[1]){
                di[el[0]] = di[x] + el[1];
                if (el[1] == 0){
                    q.push_front(el[0]);
                }
                else{
                    q.push_back(el[0]);
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        if (di[i] == 1000000000) continue;
        ans = max(ans, di[i]);
    }
    return ans;
}
int main(){
    int n, m;
    cin>>n>>m;
    map<char, int> ma;
    ma['B'] = 0;
    ma['T'] = 1;
    v.resize(n * m);
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin>>s[i];
        for (int j = 0; j < m; j++){
            if (s[i][j] == '*') continue;
            int v1 = i * m + j;
            if (i != 0 && s[i - 1][j] != '*'){
                int v2 = (i - 1) * m + j;
                v[v1].push_back({v2, ma[s[i][j]] ^ ma[s[i - 1][j]]});
                v[v2].push_back({v1, ma[s[i][j]] ^ ma[s[i - 1][j]]});
            }
            if (j != 0 && s[i][j - 1] != '*'){
                int v2 = i * m + j - 1;
                v[v1].push_back({v2, ma[s[i][j]] ^ ma[s[i][j - 1]]});
                v[v2].push_back({v1, ma[s[i][j]] ^ ma[s[i][j - 1]]});
            }
        }
    }
    cout << bfs(n * m, 0) + 1 << endl;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |