답안 #739017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739017 2023-05-09T18:39:55 Z He_Huanglu Maze (JOI23_ho_t3) C++17
43 / 100
1063 ms 20180 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;

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

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);
    for(int i = 1; i <= m; i++) {
        for(int j = 1; j <= n; j++) {
            char ch; cin >> ch;
            a[i][j] = (ch == '.' ? 1 : 0);
        }
    }
//    cout << " ^^\n";
    q[1].push({rs, cs}); f[rs][cs] = 1;
    while (!q[1].empty() || !q[0].empty()) {
//        cout << "ngu\n";
        while (!q[1].empty()) {
            int x, y; tie(x, y) = q[1].front(); q[1].pop();
//            cout << x << " " << y << " " << f[x][y] << " \n";
            q[0].push({x, y});
            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]) {
                    f[u][v] = f[x][y];
                    q[1].push({u, v});
                }
            }
        }
        while (!q[0].empty()) {
            int x, y; tie(x, y) = q[0].front(); q[0].pop();
//            cout << x << " " << y << "\n";
            int s1 = max(1, x - s), s2 = max(1, y - s);
            int s3 = min(m, x + s), s4 = min(n, y + s);
            for(int i = s1; i <= s3; i++) {
                for(int j = s2; j <= s4; j++) if(!f[i][j]) {
                    if(i == x - s && (j == y - s || j == y + s)) continue ;
                    if(i == x + s && (j == y - s || j == y + s)) continue ;
                    f[i][j] = f[x][y] + 1;
                    q[1].push({i, j});
//                    cout << i << " " << j << " **\n";
                }
            }
        }
    }
}

Compilation message

Main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main () {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("task.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("wa.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 11 ms 1564 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 7 ms 2644 KB Output is correct
32 Correct 13 ms 1588 KB Output is correct
33 Correct 9 ms 1492 KB Output is correct
34 Correct 7 ms 1492 KB Output is correct
35 Correct 7 ms 1568 KB Output is correct
36 Correct 8 ms 1632 KB Output is correct
37 Correct 11 ms 1624 KB Output is correct
38 Correct 3 ms 1492 KB Output is correct
39 Runtime error 14 ms 20160 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 240 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 368 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 372 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 368 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 3 ms 980 KB Output is correct
27 Correct 3 ms 1236 KB Output is correct
28 Correct 3 ms 1108 KB Output is correct
29 Correct 3 ms 1236 KB Output is correct
30 Correct 3 ms 1236 KB Output is correct
31 Correct 108 ms 888 KB Output is correct
32 Correct 2 ms 852 KB Output is correct
33 Correct 2 ms 852 KB Output is correct
34 Correct 7 ms 1876 KB Output is correct
35 Correct 7 ms 2644 KB Output is correct
36 Correct 7 ms 2516 KB Output is correct
37 Correct 9 ms 2836 KB Output is correct
38 Correct 7 ms 2716 KB Output is correct
39 Correct 18 ms 5336 KB Output is correct
40 Correct 72 ms 17084 KB Output is correct
41 Runtime error 16 ms 20180 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 240 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 368 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 372 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 368 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 7 ms 852 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 3 ms 724 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 5 ms 1236 KB Output is correct
40 Correct 5 ms 880 KB Output is correct
41 Correct 4 ms 852 KB Output is correct
42 Correct 3 ms 1152 KB Output is correct
43 Correct 3 ms 1364 KB Output is correct
44 Correct 3 ms 1364 KB Output is correct
45 Correct 3 ms 852 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 20 ms 852 KB Output is correct
49 Correct 34 ms 852 KB Output is correct
50 Correct 131 ms 912 KB Output is correct
51 Correct 109 ms 896 KB Output is correct
52 Correct 2 ms 852 KB Output is correct
53 Correct 2 ms 848 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 240 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 372 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 368 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 372 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 368 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 7 ms 852 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 3 ms 724 KB Output is correct
38 Correct 3 ms 1108 KB Output is correct
39 Correct 5 ms 1236 KB Output is correct
40 Correct 5 ms 880 KB Output is correct
41 Correct 4 ms 852 KB Output is correct
42 Correct 3 ms 1152 KB Output is correct
43 Correct 3 ms 1364 KB Output is correct
44 Correct 3 ms 1364 KB Output is correct
45 Correct 3 ms 852 KB Output is correct
46 Correct 3 ms 852 KB Output is correct
47 Correct 4 ms 852 KB Output is correct
48 Correct 20 ms 852 KB Output is correct
49 Correct 34 ms 852 KB Output is correct
50 Correct 131 ms 912 KB Output is correct
51 Correct 109 ms 896 KB Output is correct
52 Correct 2 ms 852 KB Output is correct
53 Correct 2 ms 848 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
55 Correct 12 ms 1676 KB Output is correct
56 Correct 4 ms 868 KB Output is correct
57 Correct 7 ms 2004 KB Output is correct
58 Correct 11 ms 1492 KB Output is correct
59 Correct 7 ms 2724 KB Output is correct
60 Correct 13 ms 1620 KB Output is correct
61 Correct 11 ms 1704 KB Output is correct
62 Correct 8 ms 2712 KB Output is correct
63 Correct 10 ms 2976 KB Output is correct
64 Correct 7 ms 2900 KB Output is correct
65 Correct 11 ms 1620 KB Output is correct
66 Correct 8 ms 1620 KB Output is correct
67 Correct 9 ms 1620 KB Output is correct
68 Correct 98 ms 1676 KB Output is correct
69 Correct 213 ms 1664 KB Output is correct
70 Correct 579 ms 1748 KB Output is correct
71 Correct 1063 ms 1908 KB Output is correct
72 Correct 9 ms 1876 KB Output is correct
73 Correct 16 ms 1660 KB Output is correct
74 Correct 4 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 11 ms 1564 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 7 ms 2644 KB Output is correct
32 Correct 13 ms 1588 KB Output is correct
33 Correct 9 ms 1492 KB Output is correct
34 Correct 7 ms 1492 KB Output is correct
35 Correct 7 ms 1568 KB Output is correct
36 Correct 8 ms 1632 KB Output is correct
37 Correct 11 ms 1624 KB Output is correct
38 Correct 3 ms 1492 KB Output is correct
39 Runtime error 14 ms 20160 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 11 ms 1564 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 7 ms 2644 KB Output is correct
32 Correct 13 ms 1588 KB Output is correct
33 Correct 9 ms 1492 KB Output is correct
34 Correct 7 ms 1492 KB Output is correct
35 Correct 7 ms 1568 KB Output is correct
36 Correct 8 ms 1632 KB Output is correct
37 Correct 11 ms 1624 KB Output is correct
38 Correct 3 ms 1492 KB Output is correct
39 Runtime error 14 ms 20160 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 1236 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 5 ms 852 KB Output is correct
24 Correct 3 ms 852 KB Output is correct
25 Correct 3 ms 852 KB Output is correct
26 Correct 2 ms 852 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 3 ms 852 KB Output is correct
29 Correct 11 ms 1564 KB Output is correct
30 Correct 4 ms 852 KB Output is correct
31 Correct 7 ms 2644 KB Output is correct
32 Correct 13 ms 1588 KB Output is correct
33 Correct 9 ms 1492 KB Output is correct
34 Correct 7 ms 1492 KB Output is correct
35 Correct 7 ms 1568 KB Output is correct
36 Correct 8 ms 1632 KB Output is correct
37 Correct 11 ms 1624 KB Output is correct
38 Correct 3 ms 1492 KB Output is correct
39 Runtime error 14 ms 20160 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -