Submission #924127

# Submission time Handle Problem Language Result Execution time Memory
924127 2024-02-08T13:45:03 Z ErJ Maze (JOI23_ho_t3) C++17
8 / 100
145 ms 72048 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<pair<ll, ll>>
#define pp pair<ll, ll>
#define qi queue<ll>
#define qp queue<pp>
#define pqi priority_queue<ll>
#define pqp priority_queue<pp>
#define mi map<ll, ll>
#define mpi map<pp, ll>
#define mip map<ll, pp>
#define mpp map<pp, pp>
#define mb map<ll, bool>
#define si set<ll>
#define sp set<pp>
#define mod 1000000007
#define rep(a, b) for(int a = 0; a < (b); a++)
#define inf 100000000111111111


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int r, s, n;
    qi q;
    cin >> r >> s >> n;
    int startr, starts, endr, ends;
    cin >> startr >> starts >> endr >> ends;
    startr--; starts--; ends--; endr--;
    vvi table(r), dist(r), distbfs(r);
    rep(i, r) {
        table[i].resize(s);
        dist[i].resize(s);
        distbfs[i].resize(s);
        rep(j, s) {
            char ch;
            cin >> ch;
            if (ch == '.') {
                table[i][j] = 0;
            }
            else {
                table[i][j] = -1;
            }
            dist[i][j] = inf;
            distbfs[i][j] = 0;
        }
    }
    vp sousedi = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
    vp sousedi2 = { {0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1} };
    vp prevdist;
    qp q1;
    q1.push({startr, starts});
    
    while (!q1.empty()) {
        pp x = q1.front();
        q1.pop();
        dist[x.first][x.second] = 0;
        prevdist.push_back(x);
        for (pp i : sousedi) {
            ll a = x.first + i.first;
            ll b = x.second + i.second;
            if (a < r && a >= 0 && b < s && b >= 0) {
                if (table[a][b] == 0 && dist[a][b] == inf) {
                    q1.push({ a, b });
                    dist[a][b] = 0;
                }
            }
        }
    }
    ll pomoc = 0;
    while (dist[endr][ends] == inf) {
        pomoc++;
        qp q2;
        for (int i = 0; i < prevdist.size(); i++) {
            for (pp j : sousedi) {
                ll a = prevdist[i].first + j.first;
                ll b = prevdist[i].second + j.second;
                if (a < r && a >= 0 && b < s && b >= 0) {
                    if (dist[a][b] == inf && distbfs[a][b] != n) {
                        q2.push({ a, b });
                        distbfs[a][b] = n;
                    }
                }
            }
        }
        prevdist.clear();
        while (!q2.empty()) {
            pp x = q2.front();
            prevdist.push_back(x);
            q2.pop();
            dist[x.first][x.second] = pomoc;
            if (distbfs[x.first][x.second] <= 1) {
                continue;
            }
            ll xd = distbfs[x.first][x.second];
            for (pp i : sousedi2) {
                ll a = x.first + i.first;
                ll b = x.second + i.second;
                if (a < r && a >= 0 && b < s && b >= 0) {
                    if (dist[a][b] == inf) {
                        dist[a][b] = pomoc;
                        q2.push({ a, b });
                        distbfs[a][b] = xd - 1;
                    }
                }
            }
        }
        qp q3;
        rep(i, prevdist.size()) {
            q3.push(prevdist[i]);
        }
        while (!q3.empty()) {
            pp x = q3.front();
            q3.pop();
            for (pp i : sousedi) {
                ll a = x.first + i.first;
                ll b = x.second + i.second;
                if (a < r && a >= 0 && b < s && b >= 0) {
                    if (dist[a][b] == inf && table[a][b] == 0) {
                        q3.push({ a, b });
                        dist[a][b] = pomoc;
                        prevdist.push_back({ a, b });
                    }
                }
            }
        }
    }
    cout << dist[endr][ends] << endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int i = 0; i < prevdist.size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
Main.cpp:24:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 | #define rep(a, b) for(int a = 0; a < (b); a++)
      |                                    ^
Main.cpp:116:9: note: in expansion of macro 'rep'
  116 |         rep(i, prevdist.size()) {
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 408 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 4 ms 1612 KB Output is correct
21 Correct 4 ms 3036 KB Output is correct
22 Correct 5 ms 1944 KB Output is correct
23 Correct 4 ms 1884 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 5 ms 1884 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 12 ms 4188 KB Output is correct
30 Correct 4 ms 1880 KB Output is correct
31 Correct 8 ms 9684 KB Output is correct
32 Correct 13 ms 4272 KB Output is correct
33 Correct 10 ms 4184 KB Output is correct
34 Correct 7 ms 3932 KB Output is correct
35 Correct 13 ms 3932 KB Output is correct
36 Correct 9 ms 4444 KB Output is correct
37 Correct 16 ms 4188 KB Output is correct
38 Correct 4 ms 4208 KB Output is correct
39 Correct 140 ms 37288 KB Output is correct
40 Correct 6 ms 4444 KB Output is correct
41 Correct 6 ms 4952 KB Output is correct
42 Correct 18 ms 5720 KB Output is correct
43 Correct 14 ms 6420 KB Output is correct
44 Correct 28 ms 18524 KB Output is correct
45 Correct 34 ms 20132 KB Output is correct
46 Correct 121 ms 72048 KB Output is correct
47 Correct 143 ms 37464 KB Output is correct
48 Correct 134 ms 37292 KB Output is correct
49 Correct 46 ms 37076 KB Output is correct
50 Correct 101 ms 37160 KB Output is correct
51 Correct 118 ms 38672 KB Output is correct
52 Correct 94 ms 37856 KB Output is correct
53 Correct 145 ms 37212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Incorrect 2 ms 1372 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 408 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 4 ms 1612 KB Output is correct
21 Correct 4 ms 3036 KB Output is correct
22 Correct 5 ms 1944 KB Output is correct
23 Correct 4 ms 1884 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 5 ms 1884 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 12 ms 4188 KB Output is correct
30 Correct 4 ms 1880 KB Output is correct
31 Correct 8 ms 9684 KB Output is correct
32 Correct 13 ms 4272 KB Output is correct
33 Correct 10 ms 4184 KB Output is correct
34 Correct 7 ms 3932 KB Output is correct
35 Correct 13 ms 3932 KB Output is correct
36 Correct 9 ms 4444 KB Output is correct
37 Correct 16 ms 4188 KB Output is correct
38 Correct 4 ms 4208 KB Output is correct
39 Correct 140 ms 37288 KB Output is correct
40 Correct 6 ms 4444 KB Output is correct
41 Correct 6 ms 4952 KB Output is correct
42 Correct 18 ms 5720 KB Output is correct
43 Correct 14 ms 6420 KB Output is correct
44 Correct 28 ms 18524 KB Output is correct
45 Correct 34 ms 20132 KB Output is correct
46 Correct 121 ms 72048 KB Output is correct
47 Correct 143 ms 37464 KB Output is correct
48 Correct 134 ms 37292 KB Output is correct
49 Correct 46 ms 37076 KB Output is correct
50 Correct 101 ms 37160 KB Output is correct
51 Correct 118 ms 38672 KB Output is correct
52 Correct 94 ms 37856 KB Output is correct
53 Correct 145 ms 37212 KB Output is correct
54 Correct 0 ms 600 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Incorrect 0 ms 348 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 408 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 4 ms 1612 KB Output is correct
21 Correct 4 ms 3036 KB Output is correct
22 Correct 5 ms 1944 KB Output is correct
23 Correct 4 ms 1884 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 5 ms 1884 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 12 ms 4188 KB Output is correct
30 Correct 4 ms 1880 KB Output is correct
31 Correct 8 ms 9684 KB Output is correct
32 Correct 13 ms 4272 KB Output is correct
33 Correct 10 ms 4184 KB Output is correct
34 Correct 7 ms 3932 KB Output is correct
35 Correct 13 ms 3932 KB Output is correct
36 Correct 9 ms 4444 KB Output is correct
37 Correct 16 ms 4188 KB Output is correct
38 Correct 4 ms 4208 KB Output is correct
39 Correct 140 ms 37288 KB Output is correct
40 Correct 6 ms 4444 KB Output is correct
41 Correct 6 ms 4952 KB Output is correct
42 Correct 18 ms 5720 KB Output is correct
43 Correct 14 ms 6420 KB Output is correct
44 Correct 28 ms 18524 KB Output is correct
45 Correct 34 ms 20132 KB Output is correct
46 Correct 121 ms 72048 KB Output is correct
47 Correct 143 ms 37464 KB Output is correct
48 Correct 134 ms 37292 KB Output is correct
49 Correct 46 ms 37076 KB Output is correct
50 Correct 101 ms 37160 KB Output is correct
51 Correct 118 ms 38672 KB Output is correct
52 Correct 94 ms 37856 KB Output is correct
53 Correct 145 ms 37212 KB Output is correct
54 Correct 0 ms 600 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Incorrect 0 ms 348 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 408 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 4 ms 1884 KB Output is correct
20 Correct 4 ms 1612 KB Output is correct
21 Correct 4 ms 3036 KB Output is correct
22 Correct 5 ms 1944 KB Output is correct
23 Correct 4 ms 1884 KB Output is correct
24 Correct 3 ms 1884 KB Output is correct
25 Correct 5 ms 1884 KB Output is correct
26 Correct 2 ms 2140 KB Output is correct
27 Correct 2 ms 1884 KB Output is correct
28 Correct 3 ms 1884 KB Output is correct
29 Correct 12 ms 4188 KB Output is correct
30 Correct 4 ms 1880 KB Output is correct
31 Correct 8 ms 9684 KB Output is correct
32 Correct 13 ms 4272 KB Output is correct
33 Correct 10 ms 4184 KB Output is correct
34 Correct 7 ms 3932 KB Output is correct
35 Correct 13 ms 3932 KB Output is correct
36 Correct 9 ms 4444 KB Output is correct
37 Correct 16 ms 4188 KB Output is correct
38 Correct 4 ms 4208 KB Output is correct
39 Correct 140 ms 37288 KB Output is correct
40 Correct 6 ms 4444 KB Output is correct
41 Correct 6 ms 4952 KB Output is correct
42 Correct 18 ms 5720 KB Output is correct
43 Correct 14 ms 6420 KB Output is correct
44 Correct 28 ms 18524 KB Output is correct
45 Correct 34 ms 20132 KB Output is correct
46 Correct 121 ms 72048 KB Output is correct
47 Correct 143 ms 37464 KB Output is correct
48 Correct 134 ms 37292 KB Output is correct
49 Correct 46 ms 37076 KB Output is correct
50 Correct 101 ms 37160 KB Output is correct
51 Correct 118 ms 38672 KB Output is correct
52 Correct 94 ms 37856 KB Output is correct
53 Correct 145 ms 37212 KB Output is correct
54 Correct 0 ms 600 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Incorrect 0 ms 348 KB Output isn't correct
62 Halted 0 ms 0 KB -