Submission #968831

# Submission time Handle Problem Language Result Execution time Memory
968831 2024-04-24T07:06:47 Z Thunnus Tracks in the Snow (BOI13_tracks) C++17
100 / 100
503 ms 235784 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define fi first
#define se second

const int MAX = 4000;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int n, m, depth[MAX][MAX], ans = 1;
string snow[MAX];

inline bool inside(int x, int y){ return x >= 0 && x < n && y >= 0 && y < m && snow[x][y] != '.';}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> snow[i];

    deque<pii> dq;
    dq.emplace_back(0, 0);
    depth[0][0] = 1;
    while(!dq.empty()){
        pii c = dq.front();
        dq.pop_front();
        ans = max(ans, depth[c.fi][c.se]);
        for(int i = 0; i < 4; i++){
            int new_x = c.fi + dx[i];
            int new_y = c.se + dy[i];
            if(inside(new_x, new_y) && depth[new_x][new_y] == 0){
                if(snow[new_x][new_y] == snow[c.fi][c.se]){
                    depth[new_x][new_y] = depth[c.fi][c.se];
                    dq.emplace_front(new_x, new_y);
                }
                else{
                    depth[new_x][new_y] = depth[c.fi][c.se] + 1;
                    dq.emplace_back(new_x, new_y);
                }
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 4952 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 5 ms 4440 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 2 ms 1840 KB Output is correct
11 Correct 2 ms 1884 KB Output is correct
12 Correct 4 ms 2652 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 8 ms 4444 KB Output is correct
16 Correct 9 ms 4956 KB Output is correct
17 Correct 6 ms 4696 KB Output is correct
18 Correct 5 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 27 ms 15132 KB Output is correct
3 Correct 133 ms 93524 KB Output is correct
4 Correct 50 ms 43092 KB Output is correct
5 Correct 89 ms 69456 KB Output is correct
6 Correct 477 ms 186288 KB Output is correct
7 Correct 11 ms 17580 KB Output is correct
8 Correct 9 ms 16704 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 7 ms 16472 KB Output is correct
12 Correct 1 ms 1388 KB Output is correct
13 Correct 27 ms 15184 KB Output is correct
14 Correct 16 ms 10060 KB Output is correct
15 Correct 12 ms 14212 KB Output is correct
16 Correct 13 ms 6676 KB Output is correct
17 Correct 71 ms 33072 KB Output is correct
18 Correct 51 ms 48076 KB Output is correct
19 Correct 49 ms 43088 KB Output is correct
20 Correct 36 ms 27220 KB Output is correct
21 Correct 99 ms 61264 KB Output is correct
22 Correct 87 ms 69420 KB Output is correct
23 Correct 136 ms 56404 KB Output is correct
24 Correct 82 ms 59136 KB Output is correct
25 Correct 321 ms 159028 KB Output is correct
26 Correct 295 ms 235784 KB Output is correct
27 Correct 361 ms 216180 KB Output is correct
28 Correct 503 ms 186792 KB Output is correct
29 Correct 466 ms 187816 KB Output is correct
30 Correct 451 ms 197096 KB Output is correct
31 Correct 375 ms 115512 KB Output is correct
32 Correct 329 ms 193828 KB Output is correct