Submission #101604

# Submission time Handle Problem Language Result Execution time Memory
101604 2019-03-19T05:02:16 Z shenxy Tracks in the Snow (BOI13_tracks) C++11
100 / 100
1820 ms 110604 KB
#include <cstdio>
#include <algorithm>
#include <deque>
#include <cstring>
#include <utility>
using namespace std;
typedef pair<int, int> coord;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int INF = 1000000000;
int main() {
    int H, W, ans = 0;
    scanf("%d %d", &H, &W);
    char mygrid[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf(" %c", &mygrid[i][j]);
        }
    }
    int visited[H][W];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            visited[i][j] = INF;
        }
    }
    visited[0][0] = 0;
    deque<coord> bfsq;
    bfsq.push_back(coord(0, 0));
    while (!bfsq.empty()) {
        coord k = bfsq.front();
        bfsq.pop_front();
        for (int i = 0; i < 4; i++) {
            if (k.first + dx[i] >= 0 && k.first + dx[i] < H && k.second + dy[i] >= 0 && k.second + dy[i] < W) {
                if (mygrid[k.first + dx[i]][k.second + dy[i]] == mygrid[k.first][k.second]) {
                    if (visited[k.first + dx[i]][k.second + dy[i]] == INF) {
                        visited[k.first + dx[i]][k.second + dy[i]] = visited[k.first][k.second];
                        bfsq.push_front(coord(k.first + dx[i], k.second + dy[i]));
                    }
                } else if (mygrid[k.first + dx[i]][k.second + dy[i]] != '.') {
                    if (visited[k.first + dx[i]][k.second + dy[i]] == INF) {
                        visited[k.first + dx[i]][k.second + dy[i]] = visited[k.first][k.second] + 1;
                        bfsq.push_back(coord(k.first + dx[i], k.second + dy[i]));
                        ans = max(ans, visited[k.first + dx[i]][k.second + dy[i]]);
                    }
                }
            }
        }
    }
    printf("%d", ans + 1);
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &H, &W);
     ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &mygrid[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1480 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 23 ms 1264 KB Output is correct
5 Correct 8 ms 640 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 4 ms 392 KB Output is correct
10 Correct 8 ms 640 KB Output is correct
11 Correct 8 ms 620 KB Output is correct
12 Correct 11 ms 768 KB Output is correct
13 Correct 11 ms 760 KB Output is correct
14 Correct 9 ms 768 KB Output is correct
15 Correct 28 ms 1632 KB Output is correct
16 Correct 27 ms 1536 KB Output is correct
17 Correct 21 ms 1408 KB Output is correct
18 Correct 15 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 123 ms 7928 KB Output is correct
3 Correct 970 ms 78624 KB Output is correct
4 Correct 300 ms 18680 KB Output is correct
5 Correct 671 ms 44428 KB Output is correct
6 Correct 1809 ms 91964 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 5 ms 432 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 175 ms 7944 KB Output is correct
14 Correct 87 ms 4928 KB Output is correct
15 Correct 65 ms 5112 KB Output is correct
16 Correct 55 ms 3448 KB Output is correct
17 Correct 330 ms 20172 KB Output is correct
18 Correct 315 ms 19832 KB Output is correct
19 Correct 243 ms 18628 KB Output is correct
20 Correct 218 ms 17180 KB Output is correct
21 Correct 555 ms 45880 KB Output is correct
22 Correct 549 ms 44372 KB Output is correct
23 Correct 579 ms 38380 KB Output is correct
24 Correct 551 ms 44828 KB Output is correct
25 Correct 1178 ms 78712 KB Output is correct
26 Correct 1416 ms 110604 KB Output is correct
27 Correct 1466 ms 96932 KB Output is correct
28 Correct 1765 ms 92152 KB Output is correct
29 Correct 1820 ms 89584 KB Output is correct
30 Correct 1665 ms 94396 KB Output is correct
31 Correct 1400 ms 50936 KB Output is correct
32 Correct 1647 ms 95728 KB Output is correct