# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1043812 |
2024-08-04T19:27:59 Z |
Shayan86 |
Maze (JOI23_ho_t3) |
C++14 |
|
72 ms |
21228 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
#define lid (id*2)
#define rid (id*2+1)
#define mid ((l+r)/2)
const ll N = 6e6 + 50;
const ll inf = 1e9;
ll n, m, k, cc, s[2], t[2];
int ax[4] = {-1, 0, 1, 0}, ay[4] = {0, -1, 0, 1};
vector<vector<char>> a;
vector<vector<int>> dist;
bool check(int i, int j){
return (i >= 0 && j >= 0 && i < n & j < m);
}
void bfs(int s1, int s2){
dist[s1][s2] = 0;
deque<pair<pii, pii>> dq;
dq.push_back({{s1, s2}, {0, 0}});
while(!dq.empty()){
auto [v, d] = dq.front();
dq.pop_front();
for(int i = 0; i < 4; i++){
int ip = v.F + ax[i], jp = v.S + ay[i];
if(!check(ip, jp)) continue;
if(abs(ax[i]) <= d.F && abs(ay[i]) <= d.S && (d.F - abs(ax[i]) + d.S - abs(ay[i])) > 0 && dist[ip][jp] > dist[v.F][v.S]){
dist[ip][jp] = dist[v.F][v.S];
dq.push_front({{ip, jp}, {d.F - abs(ax[i]), d.S - abs(ay[i])}});
}
else if(a[ip][jp] == '.' && dist[ip][jp] > dist[v.F][v.S]){
dist[ip][jp] = dist[v.F][v.S];
dq.push_front({{ip, jp}, {0, 0}});
}
if(check(ip, jp) && dist[ip][jp] > dist[v.F][v.S] + 1){
dist[ip][jp] = dist[v.F][v.S] + 1;
dq.push_back({{ip, jp}, {k-abs(ax[i]), k-abs(ay[i])}});
}
}
}
}
int main(){
fast_io;
cin >> n >> m >> k;
a.resize(n, vector<char>(m));
dist.resize(n, vector<int>(m, inf));
cin >> s[0] >> s[1] >> t[0] >> t[1];
s[0]--; s[1]--; t[0]--; t[1]--;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j];
bfs(s[0], s[1]);
cout << dist[t[0]][t[1]];
}
Compilation message
Main.cpp: In function 'bool check(int, int)':
Main.cpp:40:35: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
40 | return (i >= 0 && j >= 0 && i < n & j < m);
| ~~^~~
Main.cpp: In function 'void bfs(int, int)':
Main.cpp:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
49 | auto [v, d] = dq.front();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
0 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 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
880 KB |
Output is correct |
25 |
Correct |
2 ms |
880 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
5 ms |
1376 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
5 ms |
2396 KB |
Output is correct |
32 |
Correct |
7 ms |
1372 KB |
Output is correct |
33 |
Correct |
4 ms |
1372 KB |
Output is correct |
34 |
Correct |
4 ms |
1732 KB |
Output is correct |
35 |
Correct |
6 ms |
1736 KB |
Output is correct |
36 |
Correct |
7 ms |
1476 KB |
Output is correct |
37 |
Correct |
7 ms |
1372 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
51 ms |
8776 KB |
Output is correct |
40 |
Correct |
8 ms |
1372 KB |
Output is correct |
41 |
Correct |
6 ms |
1956 KB |
Output is correct |
42 |
Correct |
8 ms |
1628 KB |
Output is correct |
43 |
Correct |
7 ms |
2140 KB |
Output is correct |
44 |
Correct |
32 ms |
4744 KB |
Output is correct |
45 |
Correct |
28 ms |
5052 KB |
Output is correct |
46 |
Correct |
50 ms |
21228 KB |
Output is correct |
47 |
Correct |
71 ms |
8976 KB |
Output is correct |
48 |
Correct |
44 ms |
8792 KB |
Output is correct |
49 |
Correct |
38 ms |
13468 KB |
Output is correct |
50 |
Correct |
36 ms |
13468 KB |
Output is correct |
51 |
Correct |
72 ms |
9252 KB |
Output is correct |
52 |
Correct |
71 ms |
9044 KB |
Output is correct |
53 |
Correct |
48 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 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 |
0 ms |
348 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
344 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 |
0 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 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
880 KB |
Output is correct |
25 |
Correct |
2 ms |
880 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
5 ms |
1376 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
5 ms |
2396 KB |
Output is correct |
32 |
Correct |
7 ms |
1372 KB |
Output is correct |
33 |
Correct |
4 ms |
1372 KB |
Output is correct |
34 |
Correct |
4 ms |
1732 KB |
Output is correct |
35 |
Correct |
6 ms |
1736 KB |
Output is correct |
36 |
Correct |
7 ms |
1476 KB |
Output is correct |
37 |
Correct |
7 ms |
1372 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
51 ms |
8776 KB |
Output is correct |
40 |
Correct |
8 ms |
1372 KB |
Output is correct |
41 |
Correct |
6 ms |
1956 KB |
Output is correct |
42 |
Correct |
8 ms |
1628 KB |
Output is correct |
43 |
Correct |
7 ms |
2140 KB |
Output is correct |
44 |
Correct |
32 ms |
4744 KB |
Output is correct |
45 |
Correct |
28 ms |
5052 KB |
Output is correct |
46 |
Correct |
50 ms |
21228 KB |
Output is correct |
47 |
Correct |
71 ms |
8976 KB |
Output is correct |
48 |
Correct |
44 ms |
8792 KB |
Output is correct |
49 |
Correct |
38 ms |
13468 KB |
Output is correct |
50 |
Correct |
36 ms |
13468 KB |
Output is correct |
51 |
Correct |
72 ms |
9252 KB |
Output is correct |
52 |
Correct |
71 ms |
9044 KB |
Output is correct |
53 |
Correct |
48 ms |
8796 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 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 |
1 ms |
344 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 |
0 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 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
880 KB |
Output is correct |
25 |
Correct |
2 ms |
880 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
5 ms |
1376 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
5 ms |
2396 KB |
Output is correct |
32 |
Correct |
7 ms |
1372 KB |
Output is correct |
33 |
Correct |
4 ms |
1372 KB |
Output is correct |
34 |
Correct |
4 ms |
1732 KB |
Output is correct |
35 |
Correct |
6 ms |
1736 KB |
Output is correct |
36 |
Correct |
7 ms |
1476 KB |
Output is correct |
37 |
Correct |
7 ms |
1372 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
51 ms |
8776 KB |
Output is correct |
40 |
Correct |
8 ms |
1372 KB |
Output is correct |
41 |
Correct |
6 ms |
1956 KB |
Output is correct |
42 |
Correct |
8 ms |
1628 KB |
Output is correct |
43 |
Correct |
7 ms |
2140 KB |
Output is correct |
44 |
Correct |
32 ms |
4744 KB |
Output is correct |
45 |
Correct |
28 ms |
5052 KB |
Output is correct |
46 |
Correct |
50 ms |
21228 KB |
Output is correct |
47 |
Correct |
71 ms |
8976 KB |
Output is correct |
48 |
Correct |
44 ms |
8792 KB |
Output is correct |
49 |
Correct |
38 ms |
13468 KB |
Output is correct |
50 |
Correct |
36 ms |
13468 KB |
Output is correct |
51 |
Correct |
72 ms |
9252 KB |
Output is correct |
52 |
Correct |
71 ms |
9044 KB |
Output is correct |
53 |
Correct |
48 ms |
8796 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 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 |
1 ms |
344 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 |
0 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 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
456 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
860 KB |
Output is correct |
21 |
Correct |
2 ms |
1116 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
24 |
Correct |
2 ms |
880 KB |
Output is correct |
25 |
Correct |
2 ms |
880 KB |
Output is correct |
26 |
Correct |
3 ms |
860 KB |
Output is correct |
27 |
Correct |
3 ms |
860 KB |
Output is correct |
28 |
Correct |
2 ms |
604 KB |
Output is correct |
29 |
Correct |
5 ms |
1376 KB |
Output is correct |
30 |
Correct |
3 ms |
860 KB |
Output is correct |
31 |
Correct |
5 ms |
2396 KB |
Output is correct |
32 |
Correct |
7 ms |
1372 KB |
Output is correct |
33 |
Correct |
4 ms |
1372 KB |
Output is correct |
34 |
Correct |
4 ms |
1732 KB |
Output is correct |
35 |
Correct |
6 ms |
1736 KB |
Output is correct |
36 |
Correct |
7 ms |
1476 KB |
Output is correct |
37 |
Correct |
7 ms |
1372 KB |
Output is correct |
38 |
Correct |
5 ms |
1372 KB |
Output is correct |
39 |
Correct |
51 ms |
8776 KB |
Output is correct |
40 |
Correct |
8 ms |
1372 KB |
Output is correct |
41 |
Correct |
6 ms |
1956 KB |
Output is correct |
42 |
Correct |
8 ms |
1628 KB |
Output is correct |
43 |
Correct |
7 ms |
2140 KB |
Output is correct |
44 |
Correct |
32 ms |
4744 KB |
Output is correct |
45 |
Correct |
28 ms |
5052 KB |
Output is correct |
46 |
Correct |
50 ms |
21228 KB |
Output is correct |
47 |
Correct |
71 ms |
8976 KB |
Output is correct |
48 |
Correct |
44 ms |
8792 KB |
Output is correct |
49 |
Correct |
38 ms |
13468 KB |
Output is correct |
50 |
Correct |
36 ms |
13468 KB |
Output is correct |
51 |
Correct |
72 ms |
9252 KB |
Output is correct |
52 |
Correct |
71 ms |
9044 KB |
Output is correct |
53 |
Correct |
48 ms |
8796 KB |
Output is correct |
54 |
Correct |
0 ms |
344 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 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 |
- |