제출 #1278779

#제출 시각아이디문제언어결과실행 시간메모리
1278779eliminator_101Tracks in the Snow (BOI13_tracks)C++20
2.19 / 100
554 ms144924 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MAX = 4001, MOD = 1000000007;
ll t = 1, n, m, nx, ny, mx;
vector<string> v(MAX);
vector dist(MAX,vector<ll>(MAX, 1e9));


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("checklist.in", "r", stdin);
    //freopen("checklist.out", "w", stdout);
    //cin >>t;
    while(t--) {
        cin >> n >> m;
        for (int i = 0; i < n; i++) cin >> v[i];
        deque<pair<int, int>>q;
        q.push_front({0, 0});
        dist[0][0]=1;
        while(!q.empty()) {
            auto[x, y] = q.front();
            q.pop_front();
            for (int d = 0; d < 2; d++) {
                nx = x+d;
                ny = y+(1-d);
                if (nx>=n||ny>=n||v[nx][ny]=='.')continue;
                if (v[nx][ny]==v[x][y]&&dist[nx][ny]>dist[x][y]) {
                    dist[nx][ny]=dist[x][y];
                    q.push_front({nx, ny});
                }else if (v[nx][ny]!=v[x][y]&&dist[nx][ny]>dist[x][y]+1){
                    dist[nx][ny]=dist[x][y]+1;
                    q.push_back({nx, ny});
                }
            }
        }
        mx = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (dist[i][j]==1e9)continue;
                mx = max(mx, dist[i][j]);
            }
        }
        cout << mx << endl;
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...