Submission #920116

# Submission time Handle Problem Language Result Execution time Memory
920116 2024-02-02T04:50:29 Z thienbao1602 Tracks in the Snow (BOI13_tracks) C++17
2.1875 / 100
534 ms 79264 KB
#include    <bits/stdc++.h>
#define SKY
#define ll long long
#define ld long double
#define MASK(x) (1LL << x)
#define sz(x) (int)x.size()
#define ii pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define set0(d) memset(d, 0, sizeof(d))
using namespace std;

const int LOG = 20;
const int base = 311;
const ll inf = 1e18;
const int block = 400;
const ll MOD = 1e9 + 7;
const int mxN = 1e6 + 66;
const int mxN2D = 4e3 + 55;
const int x[] = {0, 1, 0, -1};
const int y[] = {1, 0, -1, 0};

int H, W;
char grid[mxN2D][mxN2D];

bool safe(int x, int y)
{
    return (x >= 0 && x < H && y >= 0 && y < W && grid[x][y] != '.');
}

void solve()
{
    cin >> H >> W;
    for (int r=0; r<H; r++)
    {
        for(int c=0; c<W; c++)
        {
            cin >> grid[r][c];
        }
    }

    deque<ii> pq;
    pq.push_back(mp(0, 0));
    vector<vector<int>> depth(H, vector<int>(W, 0));
    depth[0][0] = 1;

    int ans = 0;
    while(!pq.empty())
    {
        ii cell = pq.front();
        int u = cell.fi;
        int v = cell.se;

        ans = max(ans, depth[u][v]);
        for (int i=0; i<4; i++)
        {
            int ux = u + x[i];
            int vx = v + y[i];

            if (safe(ux, vx) && !depth[ux][vx])
            {
                depth[ux][vx] = depth[u][v] + (grid[ux][vx] != grid[u][v]);
                if (grid[ux][vx] == grid[u][v])
                {
                    pq.push_front(mp(ux, vx));
                } else
                {
                    pq.push_back(mp(ux, vx));
                }
            }
        }
        pq.pop_front();
    }
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    #ifdef SKY
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    #endif //SKY
    solve();
    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3416 KB Output isn't correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Incorrect 1 ms 2648 KB Output isn't correct
4 Incorrect 5 ms 3160 KB Output isn't correct
5 Incorrect 2 ms 2904 KB Output isn't correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Incorrect 1 ms 2648 KB Output isn't correct
8 Incorrect 1 ms 2648 KB Output isn't correct
9 Incorrect 1 ms 2648 KB Output isn't correct
10 Incorrect 1 ms 2904 KB Output isn't correct
11 Incorrect 2 ms 2648 KB Output isn't correct
12 Incorrect 2 ms 2908 KB Output isn't correct
13 Incorrect 2 ms 2904 KB Output isn't correct
14 Incorrect 2 ms 2904 KB Output isn't correct
15 Incorrect 4 ms 3672 KB Output isn't correct
16 Incorrect 4 ms 3416 KB Output isn't correct
17 Incorrect 4 ms 3416 KB Output isn't correct
18 Incorrect 5 ms 3160 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 15704 KB Output isn't correct
2 Incorrect 22 ms 12896 KB Output isn't correct
3 Incorrect 217 ms 79188 KB Output isn't correct
4 Incorrect 50 ms 23376 KB Output isn't correct
5 Incorrect 129 ms 48244 KB Output isn't correct
6 Incorrect 526 ms 79264 KB Output isn't correct
7 Incorrect 3 ms 16472 KB Output isn't correct
8 Incorrect 4 ms 15704 KB Output isn't correct
9 Incorrect 1 ms 600 KB Output isn't correct
10 Incorrect 1 ms 600 KB Output isn't correct
11 Incorrect 3 ms 16216 KB Output isn't correct
12 Incorrect 1 ms 2648 KB Output isn't correct
13 Incorrect 21 ms 12880 KB Output isn't correct
14 Incorrect 14 ms 8280 KB Output isn't correct
15 Incorrect 16 ms 8536 KB Output isn't correct
16 Incorrect 9 ms 5208 KB Output isn't correct
17 Incorrect 56 ms 24912 KB Output isn't correct
18 Incorrect 58 ms 24400 KB Output isn't correct
19 Incorrect 50 ms 23376 KB Output isn't correct
20 Incorrect 47 ms 22352 KB Output isn't correct
21 Incorrect 126 ms 49272 KB Output isn't correct
22 Incorrect 117 ms 48208 KB Output isn't correct
23 Incorrect 108 ms 41040 KB Output isn't correct
24 Incorrect 119 ms 48464 KB Output isn't correct
25 Incorrect 213 ms 78928 KB Output isn't correct
26 Correct 161 ms 63100 KB Output is correct
27 Incorrect 223 ms 78928 KB Output isn't correct
28 Incorrect 534 ms 79184 KB Output isn't correct
29 Incorrect 511 ms 79184 KB Output isn't correct
30 Incorrect 444 ms 77392 KB Output isn't correct
31 Incorrect 141 ms 55116 KB Output isn't correct
32 Incorrect 219 ms 78984 KB Output isn't correct