Submission #924153

# Submission time Handle Problem Language Result Execution time Memory
924153 2024-02-08T14:54:33 Z vjudge1 Maze (JOI23_ho_t3) C++17
8 / 100
102 ms 72672 KB
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define imp(v) for(auto edu:v)cout<<edu<<" "; cout<<"\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll MAXN=6e6+5;

ll a[MAXN];
ll n,m,k;
ll cv(ii x){return m*x.fst+x.snd;}
ii cv(ll x){return {x/m,x%m};}
vector<ii>dir={{0,1},{-1,0},{0,-1},{1,0}};
ii operator+(ii a, ii b){return {a.fst+b.fst,a.snd+b.snd};}
void operator+=(ii &a, ii b){a=a+b;}
bool allowed(ii p){
	auto [i,j]=p;
	if(i<0||i>=n||j<0||j>=m)return 0;
	return 1;
}
ll d[MAXN];
deque<ii>q;
void go(ii x, ii y, ll g=0){
	if(!allowed(y)||d[cv(y)]!=-1||(!g&&a[cv(y)]))return;
	if(!g)q.push_front(y),d[cv(y)]=d[cv(x)];
	else q.pb(y),d[cv(y)]=d[cv(x)]+1;
}
ll reach(ii x, ii e){
	return (max(abs(x.fst-e.fst),abs(x.snd-e.snd))<=k&&
	       abs(x.fst-e.fst)+abs(x.snd-e.snd)<2*k);
}
ll bfs(ii s, ii e){
	mset(d,-1);
	d[cv(s)]=0;
	q.push_front(s);
	ll res=MAXN;
	while(SZ(q)){
		auto x=q.front(); q.pop_front();
		for(auto add:dir){
			auto y=x+add;
			go(x,y);
		}
		// continue; // sb1
		auto [i,j]=x;
		if(reach(x,e))res=min(res,d[cv(x)]+1);
		for(ii y={i-k,j-k+1};y.snd<j+k;y+=dir[0])go(x,y,1);
		for(ii y={i+k,j-k+1};y.snd<j+k;y+=dir[0])go(x,y,1);
		for(ii y={i-k+1,j-k};y.fst<i+k;y+=dir[3])go(x,y,1);
		for(ii y={i-k+1,j+k};y.fst<i+k;y+=dir[3])go(x,y,1);
	}
	if(d[cv(e)]!=-1)res=min(res,d[cv(e)]);
	return res;
}

int main(){FIN;
	cin>>n>>m>>k;
	ii s,e; cin>>s.fst>>s.snd>>e.fst>>e.snd; s.fst--,s.snd--,e.fst--,e.snd--;
	fore(i,0,n*m){
		char c; cin>>c;
		a[i]=(c=='#');
	}
	cout<<bfs(s,e)<<"\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 7 ms 47768 KB Output is correct
3 Correct 7 ms 47832 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47832 KB Output is correct
6 Correct 6 ms 47704 KB Output is correct
7 Correct 7 ms 47708 KB Output is correct
8 Correct 6 ms 47800 KB Output is correct
9 Correct 6 ms 47708 KB Output is correct
10 Correct 7 ms 47960 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 6 ms 47792 KB Output is correct
13 Correct 7 ms 47784 KB Output is correct
14 Correct 6 ms 47708 KB Output is correct
15 Correct 6 ms 47704 KB Output is correct
16 Correct 7 ms 47764 KB Output is correct
17 Correct 6 ms 47960 KB Output is correct
18 Correct 6 ms 47960 KB Output is correct
19 Correct 10 ms 49752 KB Output is correct
20 Correct 8 ms 47704 KB Output is correct
21 Correct 10 ms 50268 KB Output is correct
22 Correct 10 ms 49756 KB Output is correct
23 Correct 10 ms 49756 KB Output is correct
24 Correct 10 ms 49852 KB Output is correct
25 Correct 10 ms 49756 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 10 ms 49756 KB Output is correct
28 Correct 9 ms 49916 KB Output is correct
29 Correct 15 ms 50012 KB Output is correct
30 Correct 11 ms 49752 KB Output is correct
31 Correct 14 ms 51036 KB Output is correct
32 Correct 16 ms 49920 KB Output is correct
33 Correct 15 ms 49756 KB Output is correct
34 Correct 12 ms 49756 KB Output is correct
35 Correct 13 ms 49756 KB Output is correct
36 Correct 15 ms 50016 KB Output is correct
37 Correct 15 ms 49756 KB Output is correct
38 Correct 15 ms 49756 KB Output is correct
39 Correct 87 ms 60352 KB Output is correct
40 Correct 16 ms 49756 KB Output is correct
41 Correct 15 ms 49752 KB Output is correct
42 Correct 18 ms 49756 KB Output is correct
43 Correct 17 ms 49752 KB Output is correct
44 Correct 45 ms 53852 KB Output is correct
45 Correct 46 ms 53852 KB Output is correct
46 Correct 86 ms 72672 KB Output is correct
47 Correct 94 ms 60192 KB Output is correct
48 Correct 84 ms 59996 KB Output is correct
49 Correct 63 ms 60144 KB Output is correct
50 Correct 66 ms 59996 KB Output is correct
51 Correct 101 ms 60636 KB Output is correct
52 Correct 102 ms 60108 KB Output is correct
53 Correct 86 ms 60124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 7 ms 47708 KB Output is correct
3 Correct 6 ms 47828 KB Output is correct
4 Correct 7 ms 47708 KB Output is correct
5 Correct 7 ms 47708 KB Output is correct
6 Incorrect 6 ms 47708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 6 ms 47704 KB Output is correct
3 Correct 6 ms 47708 KB Output is correct
4 Correct 6 ms 47832 KB Output is correct
5 Incorrect 7 ms 47708 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 7 ms 47708 KB Output is correct
3 Correct 6 ms 47828 KB Output is correct
4 Correct 7 ms 47708 KB Output is correct
5 Correct 7 ms 47708 KB Output is correct
6 Incorrect 6 ms 47708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 7 ms 47708 KB Output is correct
3 Correct 6 ms 47828 KB Output is correct
4 Correct 7 ms 47708 KB Output is correct
5 Correct 7 ms 47708 KB Output is correct
6 Incorrect 6 ms 47708 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 7 ms 47768 KB Output is correct
3 Correct 7 ms 47832 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47832 KB Output is correct
6 Correct 6 ms 47704 KB Output is correct
7 Correct 7 ms 47708 KB Output is correct
8 Correct 6 ms 47800 KB Output is correct
9 Correct 6 ms 47708 KB Output is correct
10 Correct 7 ms 47960 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 6 ms 47792 KB Output is correct
13 Correct 7 ms 47784 KB Output is correct
14 Correct 6 ms 47708 KB Output is correct
15 Correct 6 ms 47704 KB Output is correct
16 Correct 7 ms 47764 KB Output is correct
17 Correct 6 ms 47960 KB Output is correct
18 Correct 6 ms 47960 KB Output is correct
19 Correct 10 ms 49752 KB Output is correct
20 Correct 8 ms 47704 KB Output is correct
21 Correct 10 ms 50268 KB Output is correct
22 Correct 10 ms 49756 KB Output is correct
23 Correct 10 ms 49756 KB Output is correct
24 Correct 10 ms 49852 KB Output is correct
25 Correct 10 ms 49756 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 10 ms 49756 KB Output is correct
28 Correct 9 ms 49916 KB Output is correct
29 Correct 15 ms 50012 KB Output is correct
30 Correct 11 ms 49752 KB Output is correct
31 Correct 14 ms 51036 KB Output is correct
32 Correct 16 ms 49920 KB Output is correct
33 Correct 15 ms 49756 KB Output is correct
34 Correct 12 ms 49756 KB Output is correct
35 Correct 13 ms 49756 KB Output is correct
36 Correct 15 ms 50016 KB Output is correct
37 Correct 15 ms 49756 KB Output is correct
38 Correct 15 ms 49756 KB Output is correct
39 Correct 87 ms 60352 KB Output is correct
40 Correct 16 ms 49756 KB Output is correct
41 Correct 15 ms 49752 KB Output is correct
42 Correct 18 ms 49756 KB Output is correct
43 Correct 17 ms 49752 KB Output is correct
44 Correct 45 ms 53852 KB Output is correct
45 Correct 46 ms 53852 KB Output is correct
46 Correct 86 ms 72672 KB Output is correct
47 Correct 94 ms 60192 KB Output is correct
48 Correct 84 ms 59996 KB Output is correct
49 Correct 63 ms 60144 KB Output is correct
50 Correct 66 ms 59996 KB Output is correct
51 Correct 101 ms 60636 KB Output is correct
52 Correct 102 ms 60108 KB Output is correct
53 Correct 86 ms 60124 KB Output is correct
54 Correct 6 ms 47708 KB Output is correct
55 Correct 7 ms 47708 KB Output is correct
56 Correct 6 ms 47828 KB Output is correct
57 Correct 7 ms 47708 KB Output is correct
58 Correct 7 ms 47708 KB Output is correct
59 Incorrect 6 ms 47708 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 7 ms 47768 KB Output is correct
3 Correct 7 ms 47832 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47832 KB Output is correct
6 Correct 6 ms 47704 KB Output is correct
7 Correct 7 ms 47708 KB Output is correct
8 Correct 6 ms 47800 KB Output is correct
9 Correct 6 ms 47708 KB Output is correct
10 Correct 7 ms 47960 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 6 ms 47792 KB Output is correct
13 Correct 7 ms 47784 KB Output is correct
14 Correct 6 ms 47708 KB Output is correct
15 Correct 6 ms 47704 KB Output is correct
16 Correct 7 ms 47764 KB Output is correct
17 Correct 6 ms 47960 KB Output is correct
18 Correct 6 ms 47960 KB Output is correct
19 Correct 10 ms 49752 KB Output is correct
20 Correct 8 ms 47704 KB Output is correct
21 Correct 10 ms 50268 KB Output is correct
22 Correct 10 ms 49756 KB Output is correct
23 Correct 10 ms 49756 KB Output is correct
24 Correct 10 ms 49852 KB Output is correct
25 Correct 10 ms 49756 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 10 ms 49756 KB Output is correct
28 Correct 9 ms 49916 KB Output is correct
29 Correct 15 ms 50012 KB Output is correct
30 Correct 11 ms 49752 KB Output is correct
31 Correct 14 ms 51036 KB Output is correct
32 Correct 16 ms 49920 KB Output is correct
33 Correct 15 ms 49756 KB Output is correct
34 Correct 12 ms 49756 KB Output is correct
35 Correct 13 ms 49756 KB Output is correct
36 Correct 15 ms 50016 KB Output is correct
37 Correct 15 ms 49756 KB Output is correct
38 Correct 15 ms 49756 KB Output is correct
39 Correct 87 ms 60352 KB Output is correct
40 Correct 16 ms 49756 KB Output is correct
41 Correct 15 ms 49752 KB Output is correct
42 Correct 18 ms 49756 KB Output is correct
43 Correct 17 ms 49752 KB Output is correct
44 Correct 45 ms 53852 KB Output is correct
45 Correct 46 ms 53852 KB Output is correct
46 Correct 86 ms 72672 KB Output is correct
47 Correct 94 ms 60192 KB Output is correct
48 Correct 84 ms 59996 KB Output is correct
49 Correct 63 ms 60144 KB Output is correct
50 Correct 66 ms 59996 KB Output is correct
51 Correct 101 ms 60636 KB Output is correct
52 Correct 102 ms 60108 KB Output is correct
53 Correct 86 ms 60124 KB Output is correct
54 Correct 6 ms 47708 KB Output is correct
55 Correct 7 ms 47708 KB Output is correct
56 Correct 6 ms 47828 KB Output is correct
57 Correct 7 ms 47708 KB Output is correct
58 Correct 7 ms 47708 KB Output is correct
59 Incorrect 6 ms 47708 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 47708 KB Output is correct
2 Correct 7 ms 47768 KB Output is correct
3 Correct 7 ms 47832 KB Output is correct
4 Correct 6 ms 47708 KB Output is correct
5 Correct 6 ms 47832 KB Output is correct
6 Correct 6 ms 47704 KB Output is correct
7 Correct 7 ms 47708 KB Output is correct
8 Correct 6 ms 47800 KB Output is correct
9 Correct 6 ms 47708 KB Output is correct
10 Correct 7 ms 47960 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 6 ms 47792 KB Output is correct
13 Correct 7 ms 47784 KB Output is correct
14 Correct 6 ms 47708 KB Output is correct
15 Correct 6 ms 47704 KB Output is correct
16 Correct 7 ms 47764 KB Output is correct
17 Correct 6 ms 47960 KB Output is correct
18 Correct 6 ms 47960 KB Output is correct
19 Correct 10 ms 49752 KB Output is correct
20 Correct 8 ms 47704 KB Output is correct
21 Correct 10 ms 50268 KB Output is correct
22 Correct 10 ms 49756 KB Output is correct
23 Correct 10 ms 49756 KB Output is correct
24 Correct 10 ms 49852 KB Output is correct
25 Correct 10 ms 49756 KB Output is correct
26 Correct 10 ms 49756 KB Output is correct
27 Correct 10 ms 49756 KB Output is correct
28 Correct 9 ms 49916 KB Output is correct
29 Correct 15 ms 50012 KB Output is correct
30 Correct 11 ms 49752 KB Output is correct
31 Correct 14 ms 51036 KB Output is correct
32 Correct 16 ms 49920 KB Output is correct
33 Correct 15 ms 49756 KB Output is correct
34 Correct 12 ms 49756 KB Output is correct
35 Correct 13 ms 49756 KB Output is correct
36 Correct 15 ms 50016 KB Output is correct
37 Correct 15 ms 49756 KB Output is correct
38 Correct 15 ms 49756 KB Output is correct
39 Correct 87 ms 60352 KB Output is correct
40 Correct 16 ms 49756 KB Output is correct
41 Correct 15 ms 49752 KB Output is correct
42 Correct 18 ms 49756 KB Output is correct
43 Correct 17 ms 49752 KB Output is correct
44 Correct 45 ms 53852 KB Output is correct
45 Correct 46 ms 53852 KB Output is correct
46 Correct 86 ms 72672 KB Output is correct
47 Correct 94 ms 60192 KB Output is correct
48 Correct 84 ms 59996 KB Output is correct
49 Correct 63 ms 60144 KB Output is correct
50 Correct 66 ms 59996 KB Output is correct
51 Correct 101 ms 60636 KB Output is correct
52 Correct 102 ms 60108 KB Output is correct
53 Correct 86 ms 60124 KB Output is correct
54 Correct 6 ms 47708 KB Output is correct
55 Correct 7 ms 47708 KB Output is correct
56 Correct 6 ms 47828 KB Output is correct
57 Correct 7 ms 47708 KB Output is correct
58 Correct 7 ms 47708 KB Output is correct
59 Incorrect 6 ms 47708 KB Output isn't correct
60 Halted 0 ms 0 KB -