Submission #895550

# Submission time Handle Problem Language Result Execution time Memory
895550 2023-12-30T08:51:43 Z 123456321 Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
248 ms 93608 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1000000007;
int n,m;
#define pb push_back
#define mp make_pair
vector<vector<pair<int,int>>> adj;


void solve()
{
    cin >> n >>m ;
    vector<string> snow(n);
    for(int i = 0;i<n;i++)cin >> snow[i];
    deque<pair<int,int>> q;
    vector<vector<int>> dist(n,vector<int>(m,1e9));    
    vector<vector<int>> dir = {{1,0},{-1,0},{0,1},{0,-1}};
    q.push_back({0,0});
    dist[0][0] = 1;
    int ans = 0;
    while(!q.empty())
    {
        auto curr = q.front();
        q.pop_front();
        int x = curr.first;
        int y = curr.second;
        ans = max(ans,dist[x][y]);
        for(auto d : dir)
        {
            int nx = x + d[0];
            int ny = y + d[1];
            if(nx < 0 || nx >= n || ny < 0 || ny >= m 
            ||dist[nx][ny]==1e9)continue;
            if(snow[nx][ny] == snow[x][y])
            {
                if(dist[nx][ny] > dist[x][y])
                {
                    dist[nx][ny] = dist[x][y];
                    q.push_front({nx,ny});
                }
            }
            else
            {
                if(dist[nx][ny] > dist[x][y] + 1)
                {
                    dist[nx][ny] = dist[x][y] + 1;
                    q.push_back({nx,ny});
                }
            }
        }
    }
    cout << ans << "\n";
    return;
}
int main()
{
    int tests = 1;
    //cin >> tests;
    int i = 1;
    while (i <= tests)
    {
        //cout << "Case #"<< i<< ": ";
        solve();
        if(i!=tests)cout << "\n";
        i++;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1884 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Incorrect 3 ms 1116 KB Output isn't correct
5 Incorrect 2 ms 860 KB Output isn't correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Incorrect 0 ms 348 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 2 ms 604 KB Output isn't correct
11 Incorrect 1 ms 604 KB Output isn't correct
12 Incorrect 3 ms 860 KB Output isn't correct
13 Incorrect 2 ms 860 KB Output isn't correct
14 Incorrect 2 ms 856 KB Output isn't correct
15 Incorrect 4 ms 1700 KB Output isn't correct
16 Incorrect 4 ms 1880 KB Output isn't correct
17 Incorrect 4 ms 1628 KB Output isn't correct
18 Incorrect 3 ms 1252 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Output isn't correct
2 Incorrect 23 ms 8920 KB Output isn't correct
3 Incorrect 248 ms 93276 KB Output isn't correct
4 Incorrect 60 ms 22384 KB Output isn't correct
5 Incorrect 128 ms 46932 KB Output isn't correct
6 Incorrect 232 ms 93264 KB Output isn't correct
7 Incorrect 2 ms 860 KB Output isn't correct
8 Incorrect 2 ms 860 KB Output isn't correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 1 ms 604 KB Output isn't correct
11 Incorrect 1 ms 860 KB Output isn't correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 23 ms 8828 KB Output isn't correct
14 Incorrect 14 ms 5720 KB Output isn't correct
15 Incorrect 15 ms 6308 KB Output isn't correct
16 Incorrect 10 ms 3676 KB Output isn't correct
17 Incorrect 74 ms 23892 KB Output isn't correct
18 Incorrect 59 ms 23636 KB Output isn't correct
19 Incorrect 56 ms 22172 KB Output isn't correct
20 Incorrect 54 ms 20436 KB Output isn't correct
21 Incorrect 133 ms 48720 KB Output isn't correct
22 Incorrect 130 ms 46956 KB Output isn't correct
23 Incorrect 124 ms 40272 KB Output isn't correct
24 Incorrect 136 ms 47956 KB Output isn't correct
25 Incorrect 233 ms 93268 KB Output isn't correct
26 Correct 173 ms 61592 KB Output is correct
27 Incorrect 238 ms 93608 KB Output isn't correct
28 Incorrect 232 ms 93376 KB Output isn't correct
29 Incorrect 231 ms 93264 KB Output isn't correct
30 Incorrect 244 ms 91448 KB Output isn't correct
31 Incorrect 145 ms 52816 KB Output isn't correct
32 Incorrect 232 ms 93436 KB Output isn't correct