Submission #985029

# Submission time Handle Problem Language Result Execution time Memory
985029 2024-05-17T09:48:37 Z pannenkoek Tracks in the Snow (BOI13_tracks) C++17
56.25 / 100
164 ms 35828 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using ld = long double;
using pii = pair<ll, ll>;

const int MAXN = 2e3 + 5;
int h, w, dist[MAXN][MAXN];
char field[MAXN][MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> h >> w;
    fill(&dist[0][0], &dist[0][0] + MAXN * MAXN, -1);
    fill(&field[0][0], &field[0][0] + MAXN * MAXN, '.');

    rep(i, 0, h)
        rep(j, 0, w)
            cin >> field[i + 1][j + 1];

    deque<pii> d{{{1, 1}}};
    dist[1][1] = 1;
    int res = 0;
    while(!d.empty()){
        auto [i, j] = d.front();
        d.pop_front();
        res = dist[i][j];
        for(auto [di, dj]: vector<pii>{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}){
            if(field[i + di][j + dj] == '.') continue;
            if(dist[i + di][j + dj] >= 0) continue;
            bool same = field[i + di][j + dj] == field[i][j]; 
            dist[i + di][j + dj] = dist[i][j] + !same;
            if(same) d.push_front({i + di, j + dj});
            else d.push_back({i + di, j + dj});
        }
    }
    cout << res << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 20568 KB Output is correct
2 Correct 3 ms 20060 KB Output is correct
3 Correct 4 ms 20060 KB Output is correct
4 Correct 10 ms 20464 KB Output is correct
5 Correct 5 ms 20056 KB Output is correct
6 Correct 3 ms 20060 KB Output is correct
7 Correct 3 ms 20060 KB Output is correct
8 Correct 5 ms 20060 KB Output is correct
9 Correct 4 ms 19936 KB Output is correct
10 Correct 5 ms 19948 KB Output is correct
11 Correct 5 ms 20060 KB Output is correct
12 Correct 8 ms 20284 KB Output is correct
13 Correct 5 ms 20060 KB Output is correct
14 Correct 6 ms 20060 KB Output is correct
15 Correct 13 ms 20364 KB Output is correct
16 Correct 15 ms 20316 KB Output is correct
17 Correct 11 ms 20388 KB Output is correct
18 Correct 10 ms 20568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 20056 KB Output isn't correct
2 Correct 49 ms 21512 KB Output is correct
3 Incorrect 135 ms 35568 KB Output isn't correct
4 Correct 69 ms 23684 KB Output is correct
5 Incorrect 80 ms 28800 KB Output isn't correct
6 Incorrect 151 ms 35572 KB Output isn't correct
7 Incorrect 4 ms 20060 KB Output isn't correct
8 Incorrect 4 ms 20180 KB Output isn't correct
9 Correct 5 ms 20180 KB Output is correct
10 Incorrect 4 ms 20060 KB Output isn't correct
11 Incorrect 4 ms 19944 KB Output isn't correct
12 Correct 4 ms 20060 KB Output is correct
13 Correct 43 ms 21596 KB Output is correct
14 Correct 26 ms 20828 KB Output is correct
15 Correct 24 ms 21080 KB Output is correct
16 Correct 27 ms 20744 KB Output is correct
17 Incorrect 41 ms 23892 KB Output isn't correct
18 Correct 84 ms 23940 KB Output is correct
19 Correct 69 ms 23636 KB Output is correct
20 Correct 74 ms 23464 KB Output is correct
21 Incorrect 91 ms 29044 KB Output isn't correct
22 Incorrect 88 ms 28756 KB Output isn't correct
23 Incorrect 69 ms 27652 KB Output isn't correct
24 Incorrect 78 ms 28752 KB Output isn't correct
25 Incorrect 143 ms 35576 KB Output isn't correct
26 Correct 105 ms 31828 KB Output is correct
27 Incorrect 137 ms 35664 KB Output isn't correct
28 Incorrect 137 ms 35568 KB Output isn't correct
29 Incorrect 153 ms 35828 KB Output isn't correct
30 Incorrect 134 ms 35192 KB Output isn't correct
31 Incorrect 90 ms 30032 KB Output isn't correct
32 Incorrect 164 ms 35700 KB Output isn't correct