Submission #738930

# Submission time Handle Problem Language Result Execution time Memory
738930 2023-05-09T16:36:56 Z He_Huanglu Maze (JOI23_ho_t3) C++17
24 / 100
542 ms 775372 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;

const int N = 6e6 + 5;
int n, m, s, rs, cs, re, ce;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
vector <int> f[N], a[N], p[2][N], ok[N];
queue <ii> q[2];

int get(int t, int id, int u) {
    return p[t][id][u] == u ? u : p[t][id][u] = get(t, id, p[t][id][u]);
}

void upd(int t, int id, int i, int j, int val) {
    int u = get(t, id, i);
    while (u <= j) {
        if(t && !f[id][u]) {
            q[1].push({id, u});
            f[id][u] = val;
//            cout << id << " " << u << "***\n";
        }
        if(!t && !f[u][id]) {
            q[1].push({u, id});
            f[u][id] = val;
//            cout << u << " " << id << "***\n";
        }
        u = get(t, id, u + 1);
        p[t][id][i] = u;
    }
}

main () {
    cin.tie(0)->sync_with_stdio(0);
    if(fopen("task.inp", "r")) {
        freopen("task.inp", "r", stdin);
        freopen("wa.out", "w", stdout);
    }
    cin >> m >> n >> s >> rs >> cs >> re >> ce;
    for(int i = 1; i <= m; i++) a[i].resize(n + 1), f[i].resize(n + 1), ok[i].resize(n + 1);
    for(int i = 1; i <= m; i++) {
        for(int j = 0; j <= n + 1; j++) p[1][i].push_back(j);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= m + 1; j++) p[0][i].push_back(j);
    }
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            char ch; cin >> ch;
            a[i][j] = (ch == '.' ? 1 : 0);
        }
    }
    q[1].push({rs, cs}); f[rs][cs] = 1;
    while (!q[1].empty() || !q[0].empty()) {
        while (!q[1].empty()) {
            int x, y; tie(x, y) = q[1].front(); q[1].pop();
            q[0].push({x, y});
//            cout << x << " " << y << " " << f[x][y] << " $$\n";
            if(x == re && y == ce) return cout << f[x][y] - 1 << "\n", 0;
            for(int i = 0; i < 4; i++) {
                int u = x + dx[i], v = y + dy[i];
                if(u && u <= m && v && v <= n && !f[u][v] && a[u][v]) {
//                    cout << x << " " << y << " : " << u << " " << v << "\n";
                    f[u][v] = f[x][y];
                    q[1].push({u, v});
//                    cout << u << " " << v << "*\n";
                }
            }
        }
        while (!q[0].empty()) {
            int x, y; tie(x, y) = q[0].front(); q[0].pop();
            if(s != 1) {
//                cout << x << " " << y << "\n";
                if(x == rs && y == cs) {
                    int s1 = max(1, x - s), s2 = max(1, y - s);
                    int s3 = min(m, x + s), s4 = min(n, y + s);
//                    cout << s1 << " " << s2 << " " << s3 << " " << s4 << "\n";
                    for(int i = s1; i <= s3; i++) {
                        for(int j = s2; j <= s4; j++) if(!f[i][j]) {
                            f[i][j] = f[x][y] + 1;
                            q[1].push({i, j});
//                            cout << i << " " << j << "**\n";
                        }
                    }
                }
                else {
                    for(int i = 0; i < 4; i++) {
                        int u = x + dx[i], v = y + dy[i], val = f[x][y] + 1;
                        if(u && u <= m && v && v <= n && ok[u][v]) {
//                            if(x == 2 && y == 1) cout << u << " " << v << " " << i << " " << y + s << " ^^\n";
                            if(i == 0 && y + s <= n) upd(0, y + s, max(1, x - s), min(m, x + s), val);
                            if(i == 1 && x + s <= m) upd(1, x + s, max(1, y - s), min(n, y + s), val);
                            if(i == 2 && y - s >= 1) upd(0, y - s, max(1, x - s), min(m, x + s), val);
                            if(i == 3 && x - s >= 1) upd(1, x - s, max(1, y - s), min(n, y + s), val);
                            break ;
                        }
                    }
                }
                ok[x][y] = 1;
            }
            else {
                for(int i = 0; i < 4; i++) {
                    int u = x + dx[i], v = y + dy[i];
                    if(u && u <= m && v && v <= n && !f[u][v]) {
                        f[u][v] = f[x][y] + 1;
                        q[1].push({u, v});
//                        cout << u << " " << v << " ****\n";
                    }
                }
            }
        }
    }
}

Compilation message

Main.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main () {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("wa.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 315 ms 704880 KB Output is correct
2 Correct 317 ms 704844 KB Output is correct
3 Correct 326 ms 704816 KB Output is correct
4 Correct 337 ms 704968 KB Output is correct
5 Correct 315 ms 704992 KB Output is correct
6 Correct 321 ms 704840 KB Output is correct
7 Correct 333 ms 704844 KB Output is correct
8 Correct 318 ms 704824 KB Output is correct
9 Correct 318 ms 704808 KB Output is correct
10 Correct 313 ms 704908 KB Output is correct
11 Correct 328 ms 704696 KB Output is correct
12 Correct 324 ms 704728 KB Output is correct
13 Correct 323 ms 704712 KB Output is correct
14 Correct 311 ms 704800 KB Output is correct
15 Correct 318 ms 704904 KB Output is correct
16 Correct 319 ms 704844 KB Output is correct
17 Correct 345 ms 704772 KB Output is correct
18 Correct 327 ms 704736 KB Output is correct
19 Correct 321 ms 705936 KB Output is correct
20 Correct 317 ms 706904 KB Output is correct
21 Correct 325 ms 706392 KB Output is correct
22 Correct 319 ms 706032 KB Output is correct
23 Correct 346 ms 706008 KB Output is correct
24 Correct 317 ms 707564 KB Output is correct
25 Correct 320 ms 707752 KB Output is correct
26 Correct 314 ms 705936 KB Output is correct
27 Correct 316 ms 705968 KB Output is correct
28 Correct 329 ms 706000 KB Output is correct
29 Correct 335 ms 708148 KB Output is correct
30 Correct 318 ms 706732 KB Output is correct
31 Correct 323 ms 709168 KB Output is correct
32 Correct 335 ms 708072 KB Output is correct
33 Correct 324 ms 708164 KB Output is correct
34 Correct 359 ms 711860 KB Output is correct
35 Correct 348 ms 711836 KB Output is correct
36 Correct 321 ms 708184 KB Output is correct
37 Correct 352 ms 708232 KB Output is correct
38 Correct 339 ms 708168 KB Output is correct
39 Correct 450 ms 742148 KB Output is correct
40 Correct 323 ms 709012 KB Output is correct
41 Correct 333 ms 713408 KB Output is correct
42 Correct 330 ms 709936 KB Output is correct
43 Correct 344 ms 712372 KB Output is correct
44 Correct 387 ms 722192 KB Output is correct
45 Correct 376 ms 725000 KB Output is correct
46 Correct 366 ms 744916 KB Output is correct
47 Correct 455 ms 742124 KB Output is correct
48 Correct 434 ms 742140 KB Output is correct
49 Correct 519 ms 775260 KB Output is correct
50 Correct 542 ms 775372 KB Output is correct
51 Correct 426 ms 742740 KB Output is correct
52 Correct 452 ms 742220 KB Output is correct
53 Correct 442 ms 742272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 704812 KB Output is correct
2 Correct 315 ms 704680 KB Output is correct
3 Correct 309 ms 704744 KB Output is correct
4 Correct 310 ms 704808 KB Output is correct
5 Correct 316 ms 704768 KB Output is correct
6 Correct 311 ms 704860 KB Output is correct
7 Correct 321 ms 704792 KB Output is correct
8 Incorrect 321 ms 704716 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 339 ms 704716 KB Output is correct
2 Correct 309 ms 704716 KB Output is correct
3 Correct 318 ms 704700 KB Output is correct
4 Correct 319 ms 704972 KB Output is correct
5 Correct 317 ms 704716 KB Output is correct
6 Correct 312 ms 704804 KB Output is correct
7 Correct 313 ms 704844 KB Output is correct
8 Correct 313 ms 704844 KB Output is correct
9 Correct 317 ms 704872 KB Output is correct
10 Correct 342 ms 704844 KB Output is correct
11 Correct 324 ms 704832 KB Output is correct
12 Correct 313 ms 704828 KB Output is correct
13 Correct 314 ms 704744 KB Output is correct
14 Correct 316 ms 704736 KB Output is correct
15 Correct 313 ms 704708 KB Output is correct
16 Correct 314 ms 704768 KB Output is correct
17 Correct 315 ms 704788 KB Output is correct
18 Correct 316 ms 704708 KB Output is correct
19 Correct 317 ms 704808 KB Output is correct
20 Correct 313 ms 704772 KB Output is correct
21 Correct 319 ms 704804 KB Output is correct
22 Correct 310 ms 704832 KB Output is correct
23 Correct 317 ms 704848 KB Output is correct
24 Correct 315 ms 704964 KB Output is correct
25 Correct 313 ms 705936 KB Output is correct
26 Correct 313 ms 706480 KB Output is correct
27 Correct 319 ms 706460 KB Output is correct
28 Correct 316 ms 706448 KB Output is correct
29 Correct 314 ms 706488 KB Output is correct
30 Correct 316 ms 706564 KB Output is correct
31 Correct 323 ms 706072 KB Output is correct
32 Correct 316 ms 706096 KB Output is correct
33 Correct 316 ms 706116 KB Output is correct
34 Correct 320 ms 708416 KB Output is correct
35 Correct 323 ms 709376 KB Output is correct
36 Correct 321 ms 709328 KB Output is correct
37 Correct 324 ms 709556 KB Output is correct
38 Correct 355 ms 709444 KB Output is correct
39 Correct 365 ms 717420 KB Output is correct
40 Correct 404 ms 739372 KB Output is correct
41 Correct 371 ms 746360 KB Output is correct
42 Correct 399 ms 753652 KB Output is correct
43 Correct 399 ms 756020 KB Output is correct
44 Correct 404 ms 756184 KB Output is correct
45 Correct 412 ms 746828 KB Output is correct
46 Correct 397 ms 742576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 704812 KB Output is correct
2 Correct 315 ms 704680 KB Output is correct
3 Correct 309 ms 704744 KB Output is correct
4 Correct 310 ms 704808 KB Output is correct
5 Correct 316 ms 704768 KB Output is correct
6 Correct 311 ms 704860 KB Output is correct
7 Correct 321 ms 704792 KB Output is correct
8 Incorrect 321 ms 704716 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 321 ms 704812 KB Output is correct
2 Correct 315 ms 704680 KB Output is correct
3 Correct 309 ms 704744 KB Output is correct
4 Correct 310 ms 704808 KB Output is correct
5 Correct 316 ms 704768 KB Output is correct
6 Correct 311 ms 704860 KB Output is correct
7 Correct 321 ms 704792 KB Output is correct
8 Incorrect 321 ms 704716 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 315 ms 704880 KB Output is correct
2 Correct 317 ms 704844 KB Output is correct
3 Correct 326 ms 704816 KB Output is correct
4 Correct 337 ms 704968 KB Output is correct
5 Correct 315 ms 704992 KB Output is correct
6 Correct 321 ms 704840 KB Output is correct
7 Correct 333 ms 704844 KB Output is correct
8 Correct 318 ms 704824 KB Output is correct
9 Correct 318 ms 704808 KB Output is correct
10 Correct 313 ms 704908 KB Output is correct
11 Correct 328 ms 704696 KB Output is correct
12 Correct 324 ms 704728 KB Output is correct
13 Correct 323 ms 704712 KB Output is correct
14 Correct 311 ms 704800 KB Output is correct
15 Correct 318 ms 704904 KB Output is correct
16 Correct 319 ms 704844 KB Output is correct
17 Correct 345 ms 704772 KB Output is correct
18 Correct 327 ms 704736 KB Output is correct
19 Correct 321 ms 705936 KB Output is correct
20 Correct 317 ms 706904 KB Output is correct
21 Correct 325 ms 706392 KB Output is correct
22 Correct 319 ms 706032 KB Output is correct
23 Correct 346 ms 706008 KB Output is correct
24 Correct 317 ms 707564 KB Output is correct
25 Correct 320 ms 707752 KB Output is correct
26 Correct 314 ms 705936 KB Output is correct
27 Correct 316 ms 705968 KB Output is correct
28 Correct 329 ms 706000 KB Output is correct
29 Correct 335 ms 708148 KB Output is correct
30 Correct 318 ms 706732 KB Output is correct
31 Correct 323 ms 709168 KB Output is correct
32 Correct 335 ms 708072 KB Output is correct
33 Correct 324 ms 708164 KB Output is correct
34 Correct 359 ms 711860 KB Output is correct
35 Correct 348 ms 711836 KB Output is correct
36 Correct 321 ms 708184 KB Output is correct
37 Correct 352 ms 708232 KB Output is correct
38 Correct 339 ms 708168 KB Output is correct
39 Correct 450 ms 742148 KB Output is correct
40 Correct 323 ms 709012 KB Output is correct
41 Correct 333 ms 713408 KB Output is correct
42 Correct 330 ms 709936 KB Output is correct
43 Correct 344 ms 712372 KB Output is correct
44 Correct 387 ms 722192 KB Output is correct
45 Correct 376 ms 725000 KB Output is correct
46 Correct 366 ms 744916 KB Output is correct
47 Correct 455 ms 742124 KB Output is correct
48 Correct 434 ms 742140 KB Output is correct
49 Correct 519 ms 775260 KB Output is correct
50 Correct 542 ms 775372 KB Output is correct
51 Correct 426 ms 742740 KB Output is correct
52 Correct 452 ms 742220 KB Output is correct
53 Correct 442 ms 742272 KB Output is correct
54 Correct 321 ms 704812 KB Output is correct
55 Correct 315 ms 704680 KB Output is correct
56 Correct 309 ms 704744 KB Output is correct
57 Correct 310 ms 704808 KB Output is correct
58 Correct 316 ms 704768 KB Output is correct
59 Correct 311 ms 704860 KB Output is correct
60 Correct 321 ms 704792 KB Output is correct
61 Incorrect 321 ms 704716 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 315 ms 704880 KB Output is correct
2 Correct 317 ms 704844 KB Output is correct
3 Correct 326 ms 704816 KB Output is correct
4 Correct 337 ms 704968 KB Output is correct
5 Correct 315 ms 704992 KB Output is correct
6 Correct 321 ms 704840 KB Output is correct
7 Correct 333 ms 704844 KB Output is correct
8 Correct 318 ms 704824 KB Output is correct
9 Correct 318 ms 704808 KB Output is correct
10 Correct 313 ms 704908 KB Output is correct
11 Correct 328 ms 704696 KB Output is correct
12 Correct 324 ms 704728 KB Output is correct
13 Correct 323 ms 704712 KB Output is correct
14 Correct 311 ms 704800 KB Output is correct
15 Correct 318 ms 704904 KB Output is correct
16 Correct 319 ms 704844 KB Output is correct
17 Correct 345 ms 704772 KB Output is correct
18 Correct 327 ms 704736 KB Output is correct
19 Correct 321 ms 705936 KB Output is correct
20 Correct 317 ms 706904 KB Output is correct
21 Correct 325 ms 706392 KB Output is correct
22 Correct 319 ms 706032 KB Output is correct
23 Correct 346 ms 706008 KB Output is correct
24 Correct 317 ms 707564 KB Output is correct
25 Correct 320 ms 707752 KB Output is correct
26 Correct 314 ms 705936 KB Output is correct
27 Correct 316 ms 705968 KB Output is correct
28 Correct 329 ms 706000 KB Output is correct
29 Correct 335 ms 708148 KB Output is correct
30 Correct 318 ms 706732 KB Output is correct
31 Correct 323 ms 709168 KB Output is correct
32 Correct 335 ms 708072 KB Output is correct
33 Correct 324 ms 708164 KB Output is correct
34 Correct 359 ms 711860 KB Output is correct
35 Correct 348 ms 711836 KB Output is correct
36 Correct 321 ms 708184 KB Output is correct
37 Correct 352 ms 708232 KB Output is correct
38 Correct 339 ms 708168 KB Output is correct
39 Correct 450 ms 742148 KB Output is correct
40 Correct 323 ms 709012 KB Output is correct
41 Correct 333 ms 713408 KB Output is correct
42 Correct 330 ms 709936 KB Output is correct
43 Correct 344 ms 712372 KB Output is correct
44 Correct 387 ms 722192 KB Output is correct
45 Correct 376 ms 725000 KB Output is correct
46 Correct 366 ms 744916 KB Output is correct
47 Correct 455 ms 742124 KB Output is correct
48 Correct 434 ms 742140 KB Output is correct
49 Correct 519 ms 775260 KB Output is correct
50 Correct 542 ms 775372 KB Output is correct
51 Correct 426 ms 742740 KB Output is correct
52 Correct 452 ms 742220 KB Output is correct
53 Correct 442 ms 742272 KB Output is correct
54 Correct 321 ms 704812 KB Output is correct
55 Correct 315 ms 704680 KB Output is correct
56 Correct 309 ms 704744 KB Output is correct
57 Correct 310 ms 704808 KB Output is correct
58 Correct 316 ms 704768 KB Output is correct
59 Correct 311 ms 704860 KB Output is correct
60 Correct 321 ms 704792 KB Output is correct
61 Incorrect 321 ms 704716 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 315 ms 704880 KB Output is correct
2 Correct 317 ms 704844 KB Output is correct
3 Correct 326 ms 704816 KB Output is correct
4 Correct 337 ms 704968 KB Output is correct
5 Correct 315 ms 704992 KB Output is correct
6 Correct 321 ms 704840 KB Output is correct
7 Correct 333 ms 704844 KB Output is correct
8 Correct 318 ms 704824 KB Output is correct
9 Correct 318 ms 704808 KB Output is correct
10 Correct 313 ms 704908 KB Output is correct
11 Correct 328 ms 704696 KB Output is correct
12 Correct 324 ms 704728 KB Output is correct
13 Correct 323 ms 704712 KB Output is correct
14 Correct 311 ms 704800 KB Output is correct
15 Correct 318 ms 704904 KB Output is correct
16 Correct 319 ms 704844 KB Output is correct
17 Correct 345 ms 704772 KB Output is correct
18 Correct 327 ms 704736 KB Output is correct
19 Correct 321 ms 705936 KB Output is correct
20 Correct 317 ms 706904 KB Output is correct
21 Correct 325 ms 706392 KB Output is correct
22 Correct 319 ms 706032 KB Output is correct
23 Correct 346 ms 706008 KB Output is correct
24 Correct 317 ms 707564 KB Output is correct
25 Correct 320 ms 707752 KB Output is correct
26 Correct 314 ms 705936 KB Output is correct
27 Correct 316 ms 705968 KB Output is correct
28 Correct 329 ms 706000 KB Output is correct
29 Correct 335 ms 708148 KB Output is correct
30 Correct 318 ms 706732 KB Output is correct
31 Correct 323 ms 709168 KB Output is correct
32 Correct 335 ms 708072 KB Output is correct
33 Correct 324 ms 708164 KB Output is correct
34 Correct 359 ms 711860 KB Output is correct
35 Correct 348 ms 711836 KB Output is correct
36 Correct 321 ms 708184 KB Output is correct
37 Correct 352 ms 708232 KB Output is correct
38 Correct 339 ms 708168 KB Output is correct
39 Correct 450 ms 742148 KB Output is correct
40 Correct 323 ms 709012 KB Output is correct
41 Correct 333 ms 713408 KB Output is correct
42 Correct 330 ms 709936 KB Output is correct
43 Correct 344 ms 712372 KB Output is correct
44 Correct 387 ms 722192 KB Output is correct
45 Correct 376 ms 725000 KB Output is correct
46 Correct 366 ms 744916 KB Output is correct
47 Correct 455 ms 742124 KB Output is correct
48 Correct 434 ms 742140 KB Output is correct
49 Correct 519 ms 775260 KB Output is correct
50 Correct 542 ms 775372 KB Output is correct
51 Correct 426 ms 742740 KB Output is correct
52 Correct 452 ms 742220 KB Output is correct
53 Correct 442 ms 742272 KB Output is correct
54 Correct 321 ms 704812 KB Output is correct
55 Correct 315 ms 704680 KB Output is correct
56 Correct 309 ms 704744 KB Output is correct
57 Correct 310 ms 704808 KB Output is correct
58 Correct 316 ms 704768 KB Output is correct
59 Correct 311 ms 704860 KB Output is correct
60 Correct 321 ms 704792 KB Output is correct
61 Incorrect 321 ms 704716 KB Output isn't correct
62 Halted 0 ms 0 KB -