Submission #1334207

#TimeUsernameProblemLanguageResultExecution timeMemory
1334207ivalolreTracks in the Snow (BOI13_tracks)C++20
100 / 100
520 ms115864 KiB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define LSOne(S) ((S)&(-S))
#define all(S) S.begin(),S.end()
#define fore(V,I,F) for(int V=I;V<=F;V++)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

struct nodoCola{
    int y,x;
    int t;
    char v;
};

vpii mov = {{1,0},{0,1},{-1,0},{0,-1}};

void si(int sy, int sx, vector<string> &mapa, vvb &visto, deque<nodoCola> &cola, int tAct, char actual){
    if(sy < 0 || sx < 0 || sy >= mapa.size() || sx >= mapa[0].size())return;
    if(mapa[sy][sx] == '.' || visto[sy][sx])return;
    visto[sy][sx] = 1;
    if(mapa[sy][sx] == actual){
        cola.push_front({sy, sx, tAct, actual});
    }else{
        cola.push_back({sy,sx, tAct + 1, actual});
    }
}

int bfs(vector<string> &mapa){
    deque<nodoCola> cola;
    cola.push_front({0,0,1,mapa[0][0]});
    vvb visto(mapa.size(), vb(mapa[0].size()));

    nodoCola act,nue;
    visto[0][0] = 1;
    while(!cola.empty()){
        act = cola.front();
        cola.pop_front();
        
        for(auto [y,x] : mov){
            si(act.y - y, act.x -x, mapa, visto, cola, act.t, mapa[act.y][act.x]);
        }
    }
    return act.t;
}

void solve(){
    int n,m;
    cin >> n >> m;
    vector<string> mapa(n);
    fore(i,0,n-1)cin>>mapa[i];

    cout << bfs(mapa) << "\n";
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...