Submission #101600

# Submission time Handle Problem Language Result Execution time Memory
101600 2019-03-19T05:00:36 Z shenxy Tracks in the Snow (BOI13_tracks) C++11
97.8125 / 100
2000 ms 110468 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]));
                    }
                }
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (mygrid[i][j] != '.') ans = max(ans, visited[i][j]);
        }
    }
    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 1536 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 17 ms 1280 KB Output is correct
5 Correct 9 ms 768 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 3 ms 384 KB Output is correct
10 Correct 8 ms 688 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 13 ms 768 KB Output is correct
13 Correct 9 ms 740 KB Output is correct
14 Correct 10 ms 740 KB Output is correct
15 Correct 32 ms 1540 KB Output is correct
16 Correct 33 ms 1528 KB Output is correct
17 Correct 33 ms 1528 KB Output is correct
18 Correct 25 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 176 ms 7944 KB Output is correct
3 Correct 1321 ms 78712 KB Output is correct
4 Correct 314 ms 18744 KB Output is correct
5 Correct 657 ms 44408 KB Output is correct
6 Correct 1871 ms 92008 KB Output is correct
7 Correct 5 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 7 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 133 ms 7928 KB Output is correct
14 Correct 89 ms 4728 KB Output is correct
15 Correct 96 ms 5112 KB Output is correct
16 Correct 64 ms 3448 KB Output is correct
17 Correct 354 ms 20156 KB Output is correct
18 Correct 338 ms 20032 KB Output is correct
19 Correct 316 ms 18684 KB Output is correct
20 Correct 263 ms 17272 KB Output is correct
21 Correct 739 ms 46008 KB Output is correct
22 Correct 768 ms 44264 KB Output is correct
23 Correct 723 ms 38396 KB Output is correct
24 Correct 632 ms 44920 KB Output is correct
25 Correct 1392 ms 78588 KB Output is correct
26 Correct 1455 ms 110468 KB Output is correct
27 Correct 1673 ms 96928 KB Output is correct
28 Correct 1992 ms 91908 KB Output is correct
29 Correct 1952 ms 89584 KB Output is correct
30 Execution timed out 2061 ms 94472 KB Time limit exceeded
31 Correct 1703 ms 50928 KB Output is correct
32 Correct 1715 ms 95692 KB Output is correct