Submission #388295

# Submission time Handle Problem Language Result Execution time Memory
388295 2021-04-10T19:49:12 Z Monchito Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1458 ms 101784 KB
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
using ii = pair<int,int>;

int xd[] = {1,-1,0,0}, yd[] = {0,0,1,-1};

#define forn(i, x, n) for(int i = (x); i < (int)(n); i++)

const int MAXS = 4000;
int N, M;
char G[MAXS][MAXS];

bool inside(int i, int j){
    return (i > -1 && j > -1 && i < N && j < M && G[i][j] != '.'); 
}

int main(){
    scanf("%d%d",&N,&M); 
    forn(i,0,N) forn(j,0,M) scanf(" %c",&G[i][j]);

    deque<pair<ii, int>> Q;
    vector<vector<bool>> vis(N, vector<bool>(M, false));
    int ans=0;

    Q.push_front({{0,0},1});

    while(!Q.empty()){
        pair<ii, int> p = Q.front(); Q.pop_front();
        int d = p.second; ii pos = p.first;

        ans = max(ans, d);

        forn(i,0,4){
            int x2 = xd[i]+pos.first, y2 = yd[i]+pos.second;
            if(inside(x2, y2) && !vis[x2][y2]){
                vis[x2][y2] = true;
                if(G[pos.first][pos.second] == G[x2][y2]) Q.push_front({{x2,y2},d});
                else Q.push_back({{x2,y2},d+1});
            }
        }
    }

    printf("%d\n",ans);
    return 0;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d%d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~
tracks.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |     forn(i,0,N) forn(j,0,M) scanf(" %c",&G[i][j]);
      |                             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2508 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 15 ms 2716 KB Output is correct
5 Correct 7 ms 1484 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 700 KB Output is correct
10 Correct 6 ms 1356 KB Output is correct
11 Correct 4 ms 1228 KB Output is correct
12 Correct 10 ms 1552 KB Output is correct
13 Correct 7 ms 1492 KB Output is correct
14 Correct 7 ms 1484 KB Output is correct
15 Correct 23 ms 2508 KB Output is correct
16 Correct 24 ms 2508 KB Output is correct
17 Correct 20 ms 2384 KB Output is correct
18 Correct 15 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15564 KB Output is correct
2 Correct 118 ms 7000 KB Output is correct
3 Correct 1028 ms 33908 KB Output is correct
4 Correct 246 ms 11908 KB Output is correct
5 Correct 602 ms 22072 KB Output is correct
6 Correct 1449 ms 53860 KB Output is correct
7 Correct 10 ms 16188 KB Output is correct
8 Correct 12 ms 15552 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 3 ms 332 KB Output is correct
11 Correct 10 ms 15948 KB Output is correct
12 Correct 2 ms 844 KB Output is correct
13 Correct 116 ms 6976 KB Output is correct
14 Correct 66 ms 4868 KB Output is correct
15 Correct 65 ms 5316 KB Output is correct
16 Correct 50 ms 2600 KB Output is correct
17 Correct 306 ms 12788 KB Output is correct
18 Correct 285 ms 12584 KB Output is correct
19 Correct 241 ms 11800 KB Output is correct
20 Correct 225 ms 10948 KB Output is correct
21 Correct 590 ms 22824 KB Output is correct
22 Correct 593 ms 22176 KB Output is correct
23 Correct 578 ms 18760 KB Output is correct
24 Correct 589 ms 22628 KB Output is correct
25 Correct 1118 ms 33700 KB Output is correct
26 Correct 1139 ms 101784 KB Output is correct
27 Correct 1384 ms 73244 KB Output is correct
28 Correct 1458 ms 53840 KB Output is correct
29 Correct 1439 ms 51492 KB Output is correct
30 Correct 1384 ms 59524 KB Output is correct
31 Correct 974 ms 24904 KB Output is correct
32 Correct 1299 ms 56440 KB Output is correct