Submission #96948

# Submission time Handle Problem Language Result Execution time Memory
96948 2019-02-12T20:03:07 Z dalgerok Tracks in the Snow (BOI13_tracks) C++14
100 / 100
807 ms 94004 KB
#include<bits/stdc++.h>
using namespace std;




const int N = 4001, INF = 2e9, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};




int n, m, d[N][N];
char a[N][N];

inline bool check(int x, int y){
    return 1 <= x && x <= n && 1 <= y && y <= m;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        cin >> a[i] + 1;
        for(int j = 1; j <= m; j++){
            d[i][j] = INF;
        }
    }
    deque < pair < short, short > > q;
    q.push_back(make_pair(1, 1));
    d[1][1] = 1;
    while(!q.empty()){
        int x = q.front().first,
            y = q.front().second;
        q.pop_front();
        for(int i = 0; i < 4; i++){
            int xx = x + dx[i],
                yy = y + dy[i];
            if(check(xx, yy) && a[xx][yy] != '.'){
                int val = d[x][y] + (a[x][y] != a[xx][yy]);
                if(d[xx][yy] > val){
                    d[xx][yy] = val;
                    if(a[x][y] == a[xx][yy]){
                        q.push_front(make_pair(xx, yy));
                    }
                    else{
                        q.push_back(make_pair(xx, yy));
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(a[i][j] != '.'){
                ans = max(ans, d[i][j]);
            }
        }
    }
    cout << ans << "\n";
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin >> a[i] + 1;
                ~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5248 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 768 KB Output is correct
4 Correct 11 ms 4992 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 768 KB Output is correct
8 Correct 2 ms 896 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct
11 Correct 4 ms 2176 KB Output is correct
12 Correct 8 ms 3072 KB Output is correct
13 Correct 5 ms 2944 KB Output is correct
14 Correct 5 ms 2944 KB Output is correct
15 Correct 14 ms 5376 KB Output is correct
16 Correct 15 ms 5248 KB Output is correct
17 Correct 14 ms 5120 KB Output is correct
18 Correct 10 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 30848 KB Output is correct
2 Correct 44 ms 16384 KB Output is correct
3 Correct 215 ms 78676 KB Output is correct
4 Correct 79 ms 29952 KB Output is correct
5 Correct 149 ms 59080 KB Output is correct
6 Correct 670 ms 85536 KB Output is correct
7 Correct 24 ms 32256 KB Output is correct
8 Correct 25 ms 30848 KB Output is correct
9 Correct 3 ms 640 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 24 ms 31736 KB Output is correct
12 Correct 4 ms 1664 KB Output is correct
13 Correct 43 ms 16384 KB Output is correct
14 Correct 25 ms 11136 KB Output is correct
15 Correct 32 ms 12160 KB Output is correct
16 Correct 21 ms 6136 KB Output is correct
17 Correct 124 ms 32376 KB Output is correct
18 Correct 117 ms 31992 KB Output is correct
19 Correct 84 ms 29976 KB Output is correct
20 Correct 63 ms 27768 KB Output is correct
21 Correct 172 ms 61176 KB Output is correct
22 Correct 163 ms 59100 KB Output is correct
23 Correct 214 ms 49372 KB Output is correct
24 Correct 142 ms 60664 KB Output is correct
25 Correct 470 ms 78588 KB Output is correct
26 Correct 336 ms 94004 KB Output is correct
27 Correct 576 ms 93232 KB Output is correct
28 Correct 774 ms 85752 KB Output is correct
29 Correct 807 ms 86036 KB Output is correct
30 Correct 669 ms 87620 KB Output is correct
31 Correct 623 ms 63224 KB Output is correct
32 Correct 460 ms 87692 KB Output is correct