답안 #341724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341724 2020-12-30T19:30:30 Z alexyd88 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
985 ms 119128 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define f first
#define s second
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define vvb vector<vector<bool>>
#define piii pair<int, pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define inf 987654321
#define pb push_back
#define p push
#define ll long long
#define ull unsigned long long
#define g get
#define dbl double
#define pf push_front

int N, M;
char sn[4005][4005];
int depth[4005][4005];
int ans;
int xa[4] = {0, 0, 1, -1};
int ya[4] = {1, -1, 0, 0};

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++)
        for (int j = 0; j < M; j++)
            cin >> sn[i][j];
    deque<pii> q;
    q.pb({0, 0});
    depth[0][0] = 1;
    while (!q.empty())
    {
        int x = q.front().f, y = q.front().s;
        q.pop_front();
        ans = max(ans, depth[x][y]);
        for (int i = 0; i < 4; i++)
        {
            int nx = x + xa[i], ny = y + ya[i];
            if (nx >= 0 && nx < N && ny >= 0 && ny < M && sn[nx][ny] != '.' && !depth[nx][ny])
            {
                if (sn[x][y] == sn[nx][ny])
                {
                    depth[nx][ny] = depth[x][y];
                    q.pf({nx, ny});
                }
                else
                {
                    depth[nx][ny] = depth[x][y] + 1;
                    q.pb({nx, ny});
                }
            }
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5456 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 848 KB Output is correct
4 Correct 13 ms 5200 KB Output is correct
5 Correct 9 ms 2896 KB Output is correct
6 Correct 1 ms 592 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 2 ms 848 KB Output is correct
9 Correct 3 ms 1104 KB Output is correct
10 Correct 5 ms 2640 KB Output is correct
11 Correct 4 ms 2012 KB Output is correct
12 Correct 8 ms 2896 KB Output is correct
13 Correct 5 ms 3920 KB Output is correct
14 Correct 5 ms 3860 KB Output is correct
15 Correct 17 ms 5460 KB Output is correct
16 Correct 30 ms 5460 KB Output is correct
17 Correct 20 ms 4944 KB Output is correct
18 Correct 17 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 30920 KB Output is correct
2 Correct 111 ms 13440 KB Output is correct
3 Correct 657 ms 58292 KB Output is correct
4 Correct 191 ms 29160 KB Output is correct
5 Correct 364 ms 46268 KB Output is correct
6 Correct 881 ms 100052 KB Output is correct
7 Correct 22 ms 32280 KB Output is correct
8 Correct 22 ms 30772 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 2 ms 336 KB Output is correct
11 Correct 26 ms 32624 KB Output is correct
12 Correct 3 ms 1616 KB Output is correct
13 Correct 69 ms 13556 KB Output is correct
14 Correct 45 ms 10356 KB Output is correct
15 Correct 43 ms 12872 KB Output is correct
16 Correct 39 ms 5704 KB Output is correct
17 Correct 183 ms 24904 KB Output is correct
18 Correct 215 ms 35520 KB Output is correct
19 Correct 174 ms 31052 KB Output is correct
20 Correct 129 ms 24348 KB Output is correct
21 Correct 340 ms 43592 KB Output is correct
22 Correct 362 ms 49236 KB Output is correct
23 Correct 355 ms 40264 KB Output is correct
24 Correct 363 ms 45640 KB Output is correct
25 Correct 692 ms 78600 KB Output is correct
26 Correct 726 ms 119128 KB Output is correct
27 Correct 841 ms 97028 KB Output is correct
28 Correct 985 ms 100000 KB Output is correct
29 Correct 928 ms 89540 KB Output is correct
30 Correct 858 ms 94308 KB Output is correct
31 Correct 598 ms 63348 KB Output is correct
32 Correct 733 ms 102980 KB Output is correct