Submission #1039525

# Submission time Handle Problem Language Result Execution time Memory
1039525 2024-07-31T03:19:56 Z BaroDP Tracks in the Snow (BOI13_tracks) C++17
100 / 100
849 ms 132192 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define sz(x) int(x.size())
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define loop(i, j, n, k) for(int i = j; i <= n; i += k)
#define reloop(i, j, n, k) for (int i = j; i >= n; i +=k)

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using pii = pair<int,int>;
using pss = pair<string,string>;

const int N = 4e3;
char a[N + 5][N + 5];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int n, m, depth[N + 5][N + 5];
int ans = 1;
deque<pii>q;
bool inside (int x, int y){
    if (x < 1 || x > n || y < 1 || y > m || a[x][y] == '.')
        return false;
    return true;
}
int main(){
    cin >> n >> m;
    loop(r, 1, n, 1)
        loop(c, 1, m, 1)
            cin >> a[r][c];

    q.push_front({1, 1});
    depth[1][1] = 1;
    while(!q.empty()){
        pii top = q.front(); q.pop_front();
        int x = top.fi, y = top.se;
        ans = max(ans, depth[x][y]);

        loop(k, 0, 3, 1){
            int nx = x + dx[k], ny = y + dy[k];
            if (inside(nx, ny) && depth[nx][ny] == 0){
                if (a[nx][ny] == a[x][y]){
                    depth[nx][ny] = depth[x][y];
                    q.push_front({nx, ny});
                }else{
                    depth[nx][ny] = depth[x][y] + 1;
                    q.push_back({nx, ny});
                }
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7516 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 9 ms 5212 KB Output is correct
5 Correct 4 ms 2908 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 1112 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 3 ms 2140 KB Output is correct
12 Correct 6 ms 3164 KB Output is correct
13 Correct 4 ms 2920 KB Output is correct
14 Correct 4 ms 2908 KB Output is correct
15 Correct 13 ms 5336 KB Output is correct
16 Correct 14 ms 5300 KB Output is correct
17 Correct 12 ms 5212 KB Output is correct
18 Correct 10 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31832 KB Output is correct
2 Correct 64 ms 16208 KB Output is correct
3 Correct 542 ms 73768 KB Output is correct
4 Correct 152 ms 33616 KB Output is correct
5 Correct 324 ms 54400 KB Output is correct
6 Correct 849 ms 108048 KB Output is correct
7 Correct 13 ms 33112 KB Output is correct
8 Correct 13 ms 31836 KB Output is correct
9 Correct 3 ms 2808 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 13 ms 31576 KB Output is correct
12 Correct 2 ms 1624 KB Output is correct
13 Correct 66 ms 15040 KB Output is correct
14 Correct 41 ms 10576 KB Output is correct
15 Correct 43 ms 14164 KB Output is correct
16 Correct 27 ms 6812 KB Output is correct
17 Correct 165 ms 29780 KB Output is correct
18 Correct 149 ms 36824 KB Output is correct
19 Correct 137 ms 33620 KB Output is correct
20 Correct 119 ms 26708 KB Output is correct
21 Correct 311 ms 53552 KB Output is correct
22 Correct 307 ms 54356 KB Output is correct
23 Correct 337 ms 44880 KB Output is correct
24 Correct 302 ms 50852 KB Output is correct
25 Correct 564 ms 94416 KB Output is correct
26 Correct 716 ms 132192 KB Output is correct
27 Correct 792 ms 115972 KB Output is correct
28 Correct 845 ms 107984 KB Output is correct
29 Correct 787 ms 105164 KB Output is correct
30 Correct 821 ms 109528 KB Output is correct
31 Correct 549 ms 74532 KB Output is correct
32 Correct 796 ms 110088 KB Output is correct