답안 #790783

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790783 2023-07-23T07:58:31 Z KindaNameless Tracks in the Snow (BOI13_tracks) C++14
100 / 100
576 ms 130912 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

int dx[4] = {1, -1, 0,  0};
int dy[4] = {0,  0, 1, -1};

char M[4001][4001];
int dist[4001][4001];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int H, W; cin >> H >> W;

    for(int i = 1; i <= H; ++i){
        for(int j = 1; j <= W; ++j){
            cin >> M[i][j];
            dist[i][j] = 1e9;
        }
    }

    deque<pair<int, int>> dq;
    dq.push_front({1, 1});
    dist[1][1] = 1;

    int answer = 1;
    while(!dq.empty()){
        int x, y; tie(x, y) = dq.front(); dq.pop_front();

        for(int k = 0; k < 4; ++k){
            int nx = x + dx[k], ny = y + dy[k];
            if(nx > 0 && ny > 0 && nx <= H && ny <= W && dist[nx][ny] == 1e9 && M[nx][ny] != '.'){
                dist[nx][ny] = dist[x][y];
                if(M[x][y] != M[nx][ny]){
                    dist[nx][ny]++;
                    dq.push_back({nx, ny});
                }
                else{
                    dq.push_front({nx, ny});
                }
                answer = max(answer, dist[nx][ny]);
            }
        }
    }

    cout << answer;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5460 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 712 KB Output is correct
4 Correct 6 ms 5204 KB Output is correct
5 Correct 3 ms 3028 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 3 ms 2516 KB Output is correct
11 Correct 2 ms 2132 KB Output is correct
12 Correct 4 ms 3028 KB Output is correct
13 Correct 3 ms 3032 KB Output is correct
14 Correct 3 ms 3028 KB Output is correct
15 Correct 9 ms 5556 KB Output is correct
16 Correct 10 ms 5460 KB Output is correct
17 Correct 8 ms 5204 KB Output is correct
18 Correct 6 ms 5204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 30892 KB Output is correct
2 Correct 41 ms 17832 KB Output is correct
3 Correct 252 ms 94268 KB Output is correct
4 Correct 74 ms 33512 KB Output is correct
5 Correct 151 ms 67712 KB Output is correct
6 Correct 536 ms 107864 KB Output is correct
7 Correct 13 ms 32212 KB Output is correct
8 Correct 13 ms 30816 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 13 ms 31652 KB Output is correct
12 Correct 1 ms 1620 KB Output is correct
13 Correct 40 ms 17876 KB Output is correct
14 Correct 23 ms 11860 KB Output is correct
15 Correct 20 ms 13132 KB Output is correct
16 Correct 19 ms 6612 KB Output is correct
17 Correct 102 ms 36132 KB Output is correct
18 Correct 79 ms 35612 KB Output is correct
19 Correct 73 ms 33512 KB Output is correct
20 Correct 63 ms 31000 KB Output is correct
21 Correct 157 ms 70096 KB Output is correct
22 Correct 152 ms 67708 KB Output is correct
23 Correct 192 ms 56852 KB Output is correct
24 Correct 159 ms 69564 KB Output is correct
25 Correct 347 ms 94156 KB Output is correct
26 Correct 374 ms 130912 KB Output is correct
27 Correct 576 ms 120848 KB Output is correct
28 Correct 546 ms 107864 KB Output is correct
29 Correct 576 ms 106224 KB Output is correct
30 Correct 510 ms 110160 KB Output is correct
31 Correct 407 ms 73420 KB Output is correct
32 Correct 480 ms 109600 KB Output is correct