답안 #850457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850457 2023-09-16T15:06:11 Z thisistotallymyusername Tracks in the Snow (BOI13_tracks) C++14
100 / 100
412 ms 128700 KB
#include <iostream>
#include <cstring>
#include <algorithm>
#include <deque>

using namespace std;

typedef pair<int, int> PII;
#define F first
#define S second

const int N = 4010;

char g[N][N];
int n, m, res, d[N][N], dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

void bfs() {
    deque<PII> q; q.emplace_back(0, 0);
    memset(d, 0x3f, sizeof d); d[0][0] = 1;
    while (!q.empty()) {
        PII t = q.front(); q.pop_front();
        res = max(res, d[t.F][t.S]);
        for (int i = 0; i < 4; i++) {
            int x = t.F + dx[i], y = t.S + dy[i];
            if (0 <= x && x < n && 0 <= y && y < m && g[x][y] != '.') {
                int w = (g[x][y] != g[t.F][t.S]);
                if (d[x][y] > d[t.F][t.S] + w) {
                    d[x][y] = d[t.F][t.S] + w;
                    if (w) {
                        q.emplace_back(x, y);
                    } else {
                        q.emplace_front(x, y);
                    }
                }
            }
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", g[i]);
    bfs();
    printf("%d\n", res);
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
tracks.cpp:42:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for (int i = 0; i < n; i++) scanf("%s", g[i]);
      |                                 ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 66140 KB Output is correct
2 Correct 8 ms 64088 KB Output is correct
3 Correct 8 ms 64092 KB Output is correct
4 Correct 12 ms 66452 KB Output is correct
5 Correct 10 ms 66140 KB Output is correct
6 Correct 8 ms 64088 KB Output is correct
7 Correct 8 ms 64092 KB Output is correct
8 Correct 7 ms 64092 KB Output is correct
9 Correct 8 ms 64092 KB Output is correct
10 Correct 9 ms 66140 KB Output is correct
11 Correct 9 ms 64432 KB Output is correct
12 Correct 11 ms 66140 KB Output is correct
13 Correct 9 ms 66140 KB Output is correct
14 Correct 9 ms 66288 KB Output is correct
15 Correct 13 ms 66184 KB Output is correct
16 Correct 15 ms 66344 KB Output is correct
17 Correct 12 ms 66292 KB Output is correct
18 Correct 11 ms 66460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 78428 KB Output is correct
2 Correct 29 ms 68328 KB Output is correct
3 Correct 132 ms 78932 KB Output is correct
4 Correct 40 ms 72536 KB Output is correct
5 Correct 84 ms 76512 KB Output is correct
6 Correct 396 ms 92640 KB Output is correct
7 Correct 10 ms 79316 KB Output is correct
8 Correct 9 ms 78428 KB Output is correct
9 Correct 8 ms 64092 KB Output is correct
10 Correct 8 ms 64176 KB Output is correct
11 Correct 9 ms 78684 KB Output is correct
12 Correct 8 ms 64164 KB Output is correct
13 Correct 30 ms 68184 KB Output is correct
14 Correct 21 ms 68188 KB Output is correct
15 Correct 18 ms 68188 KB Output is correct
16 Correct 20 ms 66140 KB Output is correct
17 Correct 64 ms 72284 KB Output is correct
18 Correct 43 ms 72364 KB Output is correct
19 Correct 40 ms 72284 KB Output is correct
20 Correct 36 ms 70368 KB Output is correct
21 Correct 84 ms 76376 KB Output is correct
22 Correct 80 ms 76372 KB Output is correct
23 Correct 116 ms 74588 KB Output is correct
24 Correct 80 ms 76380 KB Output is correct
25 Correct 233 ms 79040 KB Output is correct
26 Correct 263 ms 128700 KB Output is correct
27 Correct 301 ms 105648 KB Output is correct
28 Correct 412 ms 92832 KB Output is correct
29 Correct 404 ms 90820 KB Output is correct
30 Correct 356 ms 96472 KB Output is correct
31 Correct 299 ms 77184 KB Output is correct
32 Correct 255 ms 94308 KB Output is correct