답안 #407108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407108 2021-05-18T13:28:58 Z iulia13 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
954 ms 131044 KB
#include <iostream>
#include <map>
#include <vector>
#include <deque>
using namespace std;
const int N = 4005;
char a[N][N];
int lvl[N][N];
int ans = 0;
int dL[4] = {0, 1, 0, -1};
int dC[4] = {1, 0, -1, 0};
struct NOD{
    int x, y;
};
deque <NOD> dq;
int main()
{
    int n, m, i, j;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
        cin >> a[i] + 1;
    dq.push_back({1, 1});
    lvl[1][1] = 1;
    while (!dq.empty())
    {
        int x = dq.front().x;
        int y = dq.front().y;
        ans = max(ans, lvl[x][y]);
        dq.pop_front();
        for (i = 0; i < 4; i++)
        {
            int xx = x + dL[i];
            int yy = y + dC[i];
            if (a[xx][yy] != '.' && xx >= 1 && yy >= 1 && xx <= n && yy <= m && !lvl[xx][yy])
            {
                if (a[xx][yy] == a[x][y])
                {
                    lvl[xx][yy] = lvl[x][y];
                    dq.push_front({xx, yy});
                }
                else
                {
                    lvl[xx][yy] = lvl[x][y] + 1;
                    dq.push_back({xx, yy});
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:21:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         cin >> a[i] + 1;
      |                ~~~~~^~~
tracks.cpp:18:18: warning: unused variable 'j' [-Wunused-variable]
   18 |     int n, m, i, j;
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5352 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 13 ms 5184 KB Output is correct
5 Correct 6 ms 2892 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 5 ms 2380 KB Output is correct
11 Correct 4 ms 2124 KB Output is correct
12 Correct 7 ms 3000 KB Output is correct
13 Correct 5 ms 2892 KB Output is correct
14 Correct 5 ms 2880 KB Output is correct
15 Correct 18 ms 5216 KB Output is correct
16 Correct 20 ms 5404 KB Output is correct
17 Correct 15 ms 5148 KB Output is correct
18 Correct 12 ms 5092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 30796 KB Output is correct
2 Correct 74 ms 15016 KB Output is correct
3 Correct 523 ms 73204 KB Output is correct
4 Correct 146 ms 32632 KB Output is correct
5 Correct 337 ms 53336 KB Output is correct
6 Correct 954 ms 108560 KB Output is correct
7 Correct 23 ms 32204 KB Output is correct
8 Correct 20 ms 30740 KB Output is correct
9 Correct 3 ms 588 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 21 ms 31520 KB Output is correct
12 Correct 2 ms 1612 KB Output is correct
13 Correct 81 ms 14984 KB Output is correct
14 Correct 41 ms 10352 KB Output is correct
15 Correct 42 ms 13080 KB Output is correct
16 Correct 31 ms 5648 KB Output is correct
17 Correct 189 ms 28828 KB Output is correct
18 Correct 167 ms 35596 KB Output is correct
19 Correct 149 ms 32672 KB Output is correct
20 Correct 123 ms 25468 KB Output is correct
21 Correct 312 ms 52400 KB Output is correct
22 Correct 324 ms 53288 KB Output is correct
23 Correct 360 ms 43700 KB Output is correct
24 Correct 294 ms 49652 KB Output is correct
25 Correct 744 ms 94260 KB Output is correct
26 Correct 924 ms 131044 KB Output is correct
27 Correct 884 ms 120064 KB Output is correct
28 Correct 903 ms 108644 KB Output is correct
29 Correct 914 ms 105964 KB Output is correct
30 Correct 895 ms 111168 KB Output is correct
31 Correct 656 ms 73448 KB Output is correct
32 Correct 877 ms 114068 KB Output is correct