Submission #895552

# Submission time Handle Problem Language Result Execution time Memory
895552 2023-12-30T08:54:32 Z 123456321 Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
256 ms 93408 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,0));    
    vector<vector<int>> dir = {{1,0},{-1,0},{0,1},{0,-1}};
    q.push_back({0,0});
    dist[0][0] = 1;
    int ans = 1;
    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]!=0)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 4 ms 1884 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 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 2 ms 604 KB Output isn't correct
12 Incorrect 2 ms 860 KB Output isn't correct
13 Incorrect 2 ms 860 KB Output isn't correct
14 Incorrect 3 ms 780 KB Output isn't correct
15 Incorrect 4 ms 1884 KB Output isn't correct
16 Incorrect 4 ms 1884 KB Output isn't correct
17 Incorrect 4 ms 1624 KB Output isn't correct
18 Incorrect 4 ms 1116 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 860 KB Output isn't correct
2 Incorrect 23 ms 8860 KB Output isn't correct
3 Incorrect 256 ms 93264 KB Output isn't correct
4 Incorrect 56 ms 22084 KB Output isn't correct
5 Incorrect 143 ms 47000 KB Output isn't correct
6 Incorrect 236 ms 93212 KB Output isn't correct
7 Incorrect 1 ms 860 KB Output isn't correct
8 Incorrect 2 ms 808 KB Output isn't correct
9 Incorrect 1 ms 604 KB Output isn't correct
10 Incorrect 1 ms 600 KB Output isn't correct
11 Incorrect 2 ms 860 KB Output isn't correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 24 ms 8780 KB Output isn't correct
14 Incorrect 14 ms 5724 KB Output isn't correct
15 Incorrect 15 ms 6232 KB Output isn't correct
16 Incorrect 10 ms 3676 KB Output isn't correct
17 Incorrect 63 ms 23920 KB Output isn't correct
18 Incorrect 60 ms 23636 KB Output isn't correct
19 Incorrect 56 ms 22100 KB Output isn't correct
20 Incorrect 66 ms 20428 KB Output isn't correct
21 Incorrect 140 ms 48724 KB Output isn't correct
22 Incorrect 133 ms 47084 KB Output isn't correct
23 Incorrect 155 ms 40296 KB Output isn't correct
24 Incorrect 135 ms 47952 KB Output isn't correct
25 Incorrect 233 ms 93392 KB Output isn't correct
26 Correct 208 ms 61688 KB Output is correct
27 Incorrect 240 ms 93268 KB Output isn't correct
28 Incorrect 233 ms 93268 KB Output isn't correct
29 Incorrect 233 ms 93348 KB Output isn't correct
30 Incorrect 237 ms 91476 KB Output isn't correct
31 Incorrect 149 ms 52732 KB Output isn't correct
32 Incorrect 240 ms 93408 KB Output isn't correct