Submission #949952

# Submission time Handle Problem Language Result Execution time Memory
949952 2024-03-20T00:54:57 Z chromatic Tracks in the Snow (BOI13_tracks) C++17
100 / 100
867 ms 148260 KB
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

const int MAX_H=4000,MAX_W=4000;
bool visited[MAX_H][MAX_W];
char grid[MAX_H][MAX_W];
int dist[MAX_H][MAX_W];

//L,R,U,D
vector<int> dx={0,0,-1,1};
vector<int> dy={-1,1,0,0};

int main() {
    int h,w; cin >> h >> w;
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            cin >> grid[i][j];
        }
    }
    deque<pair<int,int>> q;
    dist[0][0]=1;
    q.push_back(make_pair(0,0));
    visited[0][0]=1;
    while(!q.empty()) {
        pair<int,int> v=q.front();
        q.pop_front();
        for(int i=0; i<4; i++) {
            pair<int,int> u={v.first+dx[i],v.second+dy[i]};
            if(u.first<0 || u.first>=h || u.second<0 || u.second>=w || visited[u.first][u.second] || grid[u.first][u.second]=='.') continue;
            if(grid[v.first][v.second]==grid[u.first][u.second]) {
                dist[u.first][u.second]=dist[v.first][v.second];
                q.push_front(make_pair(u.first,u.second));
                visited[u.first][u.second]=1;
            }
            else {
                dist[u.first][u.second]=dist[v.first][v.second]+1;
                q.push_back(make_pair(u.first,u.second));
                visited[u.first][u.second]=1;
            }
        }
    }
    int ans=0;
    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            if(visited[i][j]) ans=max(ans,dist[i][j]);
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 15024 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 9 ms 15192 KB Output is correct
5 Correct 5 ms 10840 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 4 ms 8540 KB Output is correct
11 Correct 4 ms 8740 KB Output is correct
12 Correct 7 ms 10844 KB Output is correct
13 Correct 5 ms 10844 KB Output is correct
14 Correct 6 ms 10584 KB Output is correct
15 Correct 15 ms 14936 KB Output is correct
16 Correct 16 ms 14940 KB Output is correct
17 Correct 14 ms 14944 KB Output is correct
18 Correct 11 ms 15196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 93524 KB Output is correct
2 Correct 88 ms 33616 KB Output is correct
3 Correct 621 ms 109860 KB Output is correct
4 Correct 159 ms 52512 KB Output is correct
5 Correct 373 ms 83024 KB Output is correct
6 Correct 867 ms 122788 KB Output is correct
7 Correct 16 ms 94040 KB Output is correct
8 Correct 16 ms 93528 KB Output is correct
9 Correct 4 ms 6648 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 18 ms 93788 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 77 ms 33620 KB Output is correct
14 Correct 44 ms 25428 KB Output is correct
15 Correct 51 ms 28072 KB Output is correct
16 Correct 35 ms 13404 KB Output is correct
17 Correct 193 ms 55376 KB Output is correct
18 Correct 174 ms 55480 KB Output is correct
19 Correct 158 ms 52672 KB Output is correct
20 Correct 143 ms 47896 KB Output is correct
21 Correct 392 ms 76392 KB Output is correct
22 Correct 404 ms 82596 KB Output is correct
23 Correct 365 ms 69280 KB Output is correct
24 Correct 351 ms 76460 KB Output is correct
25 Correct 741 ms 94332 KB Output is correct
26 Correct 688 ms 148260 KB Output is correct
27 Correct 813 ms 129544 KB Output is correct
28 Correct 866 ms 122792 KB Output is correct
29 Correct 858 ms 121492 KB Output is correct
30 Correct 839 ms 122396 KB Output is correct
31 Correct 624 ms 89252 KB Output is correct
32 Correct 827 ms 122596 KB Output is correct