Submission #439914

# Submission time Handle Problem Language Result Execution time Memory
439914 2021-07-01T08:01:03 Z harshith828 Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1058 ms 135792 KB
#include <bits/stdc++.h>
using namespace std;

int dx[4]{1,-1,0,0}, dy[4]{0,0,1,-1};
int n,m, ans = 1;
vector<vector<int>> depth;
vector<string> snow;

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

int main(){
    cin >> n >> m;
    depth.resize(n,vector<int>(m,0));
    snow.resize(n);
    for(int i = 0;i < n;i++){
        cin >> snow[i];
        //cout << snow[i].length();
        //cout << "\n";
    }
    deque<pair<int,int>> q;
    q.push_back({0,0});
    depth[0][0] = 1;
    while(!q.empty()){
        pair<int,int> c = q.front();
        q.pop_front();
        ans = max(ans, depth[c.first][c.second]);

        for(int i = 0;i < 4;i++){
            int x = c.first + dx[i],y = c.second + dy[i];
            if(inside(x,y) && !depth[x][y]){
                if(snow[x][y] == snow[c.first][c.second]){
                    depth[x][y] = depth[c.first][c.second];
                    q.push_front({x,y});
                }
                else{
                    depth[x][y] = depth[c.first][c.second] + 1;
                    q.push_back({x,y});
                }
                
            }
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1996 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 10 ms 1508 KB Output is correct
5 Correct 4 ms 844 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 4 ms 652 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 7 ms 908 KB Output is correct
13 Correct 5 ms 844 KB Output is correct
14 Correct 4 ms 844 KB Output is correct
15 Correct 16 ms 2056 KB Output is correct
16 Correct 18 ms 1996 KB Output is correct
17 Correct 13 ms 1868 KB Output is correct
18 Correct 10 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 78 ms 10308 KB Output is correct
3 Correct 557 ms 108824 KB Output is correct
4 Correct 163 ms 25900 KB Output is correct
5 Correct 372 ms 55876 KB Output is correct
6 Correct 1058 ms 122716 KB Output is correct
7 Correct 3 ms 716 KB Output is correct
8 Correct 3 ms 716 KB Output is correct
9 Correct 4 ms 716 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 3 ms 716 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 78 ms 10320 KB Output is correct
14 Correct 42 ms 6464 KB Output is correct
15 Correct 41 ms 7012 KB Output is correct
16 Correct 32 ms 4208 KB Output is correct
17 Correct 203 ms 27892 KB Output is correct
18 Correct 176 ms 27424 KB Output is correct
19 Correct 149 ms 25796 KB Output is correct
20 Correct 123 ms 23848 KB Output is correct
21 Correct 349 ms 57752 KB Output is correct
22 Correct 362 ms 55748 KB Output is correct
23 Correct 384 ms 47784 KB Output is correct
24 Correct 333 ms 56596 KB Output is correct
25 Correct 864 ms 108960 KB Output is correct
26 Correct 689 ms 123820 KB Output is correct
27 Correct 928 ms 135792 KB Output is correct
28 Correct 1025 ms 122552 KB Output is correct
29 Correct 1024 ms 121020 KB Output is correct
30 Correct 961 ms 124484 KB Output is correct
31 Correct 759 ms 63224 KB Output is correct
32 Correct 855 ms 124288 KB Output is correct