Submission #985035

# Submission time Handle Problem Language Result Execution time Memory
985035 2024-05-17T09:50:55 Z pannenkoek Tracks in the Snow (BOI13_tracks) C++14
100 / 100
707 ms 179456 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 = 4e3 + 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;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         auto [i, j] = d.front();
      |              ^
tracks.cpp:36:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   36 |         for(auto [di, dj]: vector<pii>{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}){
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 40 ms 78932 KB Output is correct
2 Correct 11 ms 78684 KB Output is correct
3 Correct 11 ms 78684 KB Output is correct
4 Correct 17 ms 79196 KB Output is correct
5 Correct 12 ms 78680 KB Output is correct
6 Correct 11 ms 78684 KB Output is correct
7 Correct 11 ms 78684 KB Output is correct
8 Correct 11 ms 78940 KB Output is correct
9 Correct 11 ms 78908 KB Output is correct
10 Correct 13 ms 78940 KB Output is correct
11 Correct 12 ms 78940 KB Output is correct
12 Correct 14 ms 79004 KB Output is correct
13 Correct 13 ms 78956 KB Output is correct
14 Correct 12 ms 78940 KB Output is correct
15 Correct 20 ms 78940 KB Output is correct
16 Correct 24 ms 78936 KB Output is correct
17 Correct 19 ms 78940 KB Output is correct
18 Correct 17 ms 79192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 78680 KB Output is correct
2 Correct 52 ms 78936 KB Output is correct
3 Correct 280 ms 78932 KB Output is correct
4 Correct 76 ms 78924 KB Output is correct
5 Correct 190 ms 78904 KB Output is correct
6 Correct 697 ms 106168 KB Output is correct
7 Correct 12 ms 78680 KB Output is correct
8 Correct 12 ms 79192 KB Output is correct
9 Correct 12 ms 79192 KB Output is correct
10 Correct 11 ms 78684 KB Output is correct
11 Correct 12 ms 78684 KB Output is correct
12 Correct 11 ms 78692 KB Output is correct
13 Correct 52 ms 78940 KB Output is correct
14 Correct 35 ms 78940 KB Output is correct
15 Correct 31 ms 78684 KB Output is correct
16 Correct 31 ms 78944 KB Output is correct
17 Correct 120 ms 78932 KB Output is correct
18 Correct 93 ms 78912 KB Output is correct
19 Correct 88 ms 78932 KB Output is correct
20 Correct 77 ms 78916 KB Output is correct
21 Correct 180 ms 78908 KB Output is correct
22 Correct 189 ms 78684 KB Output is correct
23 Correct 228 ms 78932 KB Output is correct
24 Correct 178 ms 78940 KB Output is correct
25 Correct 472 ms 78684 KB Output is correct
26 Correct 472 ms 179456 KB Output is correct
27 Correct 620 ms 132168 KB Output is correct
28 Correct 707 ms 106176 KB Output is correct
29 Correct 689 ms 102820 KB Output is correct
30 Correct 647 ms 114632 KB Output is correct
31 Correct 513 ms 79772 KB Output is correct
32 Correct 537 ms 109608 KB Output is correct