Submission #590129

# Submission time Handle Problem Language Result Execution time Memory
590129 2022-07-05T14:41:42 Z Minhho Tracks in the Snow (BOI13_tracks) C++17
19.7917 / 100
748 ms 184400 KB
#define taskname "1"
#include <bits/stdc++.h>
#define iii tuple<int,int,int>

using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}, maxn = 4010;
int a[maxn][maxn], d[maxn][maxn], w, h;
deque<iii> dq;

bool val(int i, int j) {return min(i, j) >= 1 && i <= w && j <= h && a[i][j] != -1;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    //freopen("1.inp", "r", stdin);
    cin>>w>>h;
    char c;
    for (int i=1; i<=w; i++) for (int j=1; j<=h; j++) cin>>c, a[i][j] = c != '.' ? c : -1, d[i][j] = maxn * maxn;
    d[1][1] = 1;
    dq.emplace_back(1, 1, 1);
    while (!dq.empty())
    {
        auto [i, j, dij] = dq.front(); dq.pop_front();
        if (dij != d[i][j]) continue;
        for (int k=0; k<4; k++)
        {
            int ci = i + dx[k], cj = j + dy[k];
            if (val(ci, cj))
            {
                int wt = a[i][j] != a[ci][cj];
                if (dij + wt < d[ci][cj])
                {
                    d[ci][cj] = dij + wt;
                    if (wt) dq.emplace_back(ci, cj, dij+wt);
                    else dq.emplace_front(ci, cj, dij+wt);
                }
            }
        }
    }
    int ans = -1;
    for (int i=1; i<=w; i++) for (int j=1; j<=h; j++) ans = max(ans, d[i][j]);
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 6144 KB Output isn't correct
2 Incorrect 0 ms 468 KB Output isn't correct
3 Incorrect 1 ms 724 KB Output isn't correct
4 Correct 8 ms 5716 KB Output is correct
5 Incorrect 5 ms 3196 KB Output isn't correct
6 Incorrect 0 ms 468 KB Output isn't correct
7 Incorrect 1 ms 724 KB Output isn't correct
8 Correct 1 ms 852 KB Output is correct
9 Incorrect 1 ms 1108 KB Output isn't correct
10 Incorrect 4 ms 2772 KB Output isn't correct
11 Correct 4 ms 2260 KB Output is correct
12 Incorrect 6 ms 3284 KB Output isn't correct
13 Incorrect 4 ms 3284 KB Output isn't correct
14 Incorrect 4 ms 3284 KB Output isn't correct
15 Incorrect 11 ms 6356 KB Output isn't correct
16 Incorrect 13 ms 6256 KB Output isn't correct
17 Incorrect 10 ms 5972 KB Output isn't correct
18 Correct 9 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 31444 KB Output isn't correct
2 Incorrect 63 ms 22520 KB Output isn't correct
3 Incorrect 366 ms 125816 KB Output isn't correct
4 Incorrect 99 ms 44664 KB Output isn't correct
5 Incorrect 217 ms 94488 KB Output isn't correct
6 Correct 748 ms 146660 KB Output is correct
7 Incorrect 15 ms 32852 KB Output isn't correct
8 Incorrect 18 ms 31484 KB Output isn't correct
9 Incorrect 3 ms 852 KB Output isn't correct
10 Incorrect 1 ms 468 KB Output isn't correct
11 Incorrect 14 ms 32324 KB Output isn't correct
12 Incorrect 1 ms 1620 KB Output isn't correct
13 Incorrect 53 ms 22632 KB Output isn't correct
14 Incorrect 33 ms 14676 KB Output isn't correct
15 Incorrect 30 ms 16084 KB Output isn't correct
16 Incorrect 25 ms 8580 KB Output isn't correct
17 Incorrect 169 ms 48240 KB Output isn't correct
18 Incorrect 129 ms 47680 KB Output isn't correct
19 Incorrect 114 ms 44748 KB Output isn't correct
20 Incorrect 93 ms 41252 KB Output isn't correct
21 Incorrect 236 ms 97664 KB Output isn't correct
22 Incorrect 238 ms 94384 KB Output isn't correct
23 Incorrect 273 ms 78860 KB Output isn't correct
24 Incorrect 222 ms 96464 KB Output isn't correct
25 Incorrect 516 ms 125880 KB Output isn't correct
26 Correct 525 ms 184400 KB Output is correct
27 Correct 723 ms 176996 KB Output is correct
28 Correct 740 ms 146580 KB Output is correct
29 Correct 739 ms 142952 KB Output is correct
30 Correct 705 ms 151620 KB Output is correct
31 Incorrect 568 ms 101424 KB Output isn't correct
32 Incorrect 632 ms 161756 KB Output isn't correct