Submission #1257793

#TimeUsernameProblemLanguageResultExecution timeMemory
1257793gohannTracks in the Snow (BOI13_tracks)C++20
93.44 / 100
2102 ms464876 KiB
#include<bits/stdc++.h>
using namespace std;
#define __ ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
#define pb push_back

const vector<vector<int>> directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<vector<int>> vis(4001,vector<int>(4001));

int main(){__
    int H, W; cin >> H >> W;
    int operations = 0;
    int maxi = 0;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    vector<vector<int>> distance(H, vector<int>(W, 1e9));

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> grid[i][j];
        }
    }
    
    deque<vector<int>> d;
    d.push_front({0, 0, 0});
    distance[0][0] = 0;
    while(!d.empty()){
        vector<int> a = d.front();
        int x = d.front()[0];
        int y = d.front()[1];
        int w = d.front()[2];
        d.pop_front();  
        maxi = max(maxi, distance[x][y]);
        if(vis[x][y]) continue;
        vis[x][y]=1;
        
        for(auto dir : directions){
            int nx = x + dir[0];
            int ny = y + dir[1];
            if(nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
            if(grid[nx][ny] == '.') continue;
            
            int nw = !(grid[x][y] == grid[nx][ny]);
            if(distance[x][y] + nw < distance[nx][ny]){
                //cout << nx << " " << ny << "\n";
                distance[nx][ny] = distance[x][y] + nw;
                if(nw == 1){
                    d.push_back({nx, ny, nw});
                }
                else if(nw == 0){
                    d.push_front({nx, ny, nw});
                }
            }
        }
    }

    cout << maxi + 1;
}  
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...