Submission #1261548

#TimeUsernameProblemLanguageResultExecution timeMemory
1261548bitchgolgaTracks in the Snow (BOI13_tracks)C++20
89.06 / 100
2100 ms150644 KiB
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define float long double
#define fr(i, a, b, jump) for (int i = (int)(a); i < (int)(b); i += (int)(jump))
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define si set<int>
#define size(a) (int)(a.size())
#define all(a) a.begin(), a.end()
#define pb push_back
#define line "\n"
#define pyes cout << "Yes" << line
#define pno cout << "No" << line

void in(vi &arr, int length){arr.resize(length);fr(i,0,length,1){cin >> arr[i];}}
int binexp(int a, int b){int res = 1;while (b > 0){if (b & 1){res = res * a;}a = a * a;b >>= 1;}return res;}

void solve()
{   
    int n, m; cin >> n >> m;
    vvi grid(n, vi(m));
    fr(i, 0, n, 1){
        fr(j, 0, m, 1){
            char x; cin >> x;
            if (x == '.'){
                grid[i][j] = -1;
            }
            else{
                grid[i][j] = (x == 'F') ? 1 : 0;
            }
        }
    }
    vector<pi> dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
    priority_queue<pair<int, pi>> q;
    q.push({0, {0, 0}});
    vvi val(n, vi(m, -1));
    val[0][0] = 1;
    int ans = 1;
    while (size(q)){
        auto [idk, p] = q.top();q.pop();
        auto [i, j] = p;
        for (auto [x, y] : dir){
            if (x + i >= 0 && x + i < n && y + j >= 0 && y + j < m){
                int ni = i + x;
                int nj = j + y;
                if (val[ni][nj] == -1 && grid[ni][nj] != -1){
                    if (grid[i][j] == grid[ni][nj]){
                        val[ni][nj] = val[i][j];
                    }
                    else{
                        val[ni][nj] = 1 + val[i][j];
                        ans = max(ans, val[ni][nj]);
                    }
                    q.push({-val[ni][nj], {ni, nj}});
                }
            }
        }
    }
    cout << ans << line;
}
     
signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...