Submission #1093796

# Submission time Handle Problem Language Result Execution time Memory
1093796 2024-09-27T14:01:32 Z Abito Maze (JOI23_ho_t3) C++17
8 / 100
95 ms 88492 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=1300;
int n,m,k,sx,sy,ex,ey,mvx[]={1,0,-1,0},mvy[]={0,1,0,-1};
bool ok(int x,int y){
	return x>=1 && x<=n && y>=1 && y<=m;
}
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n>>m>>k>>sx>>sy>>ex>>ey;
	int dis[n+5][m+5],p[n+5][m+5];
	char a[n+5][m+5];
	bool vis[n+5][m+5];
	for (int i=0;i<n+5;i++){
		for (int j=0;j<m+5;j++){
			vis[i][j]=0;
			dis[i][j]=INT_MAX;
			p[i][j]=0;
			if (i && i<=n && j && j<=m) cin>>a[i][j];
		}
	}
	if ((2*k+1)*(2*k+1)<=N){
		deque<pair<int,int>> dq;
		dq.push_front({sx,sy});
		dis[sx][sy]=0;
		while (!dq.empty()){
			int x=dq.front().F,y=dq.front().S;
			dq.pop_front();
			if (vis[x][y]) continue;
			//cout<<x<<' '<<y<<' '<<dis[x][y]<<endl;
			vis[x][y]=1;
			for (int i=0;i<4;i++){
				int nx=mvx[i]+x,ny=mvy[i]+y;
				if (!ok(nx,ny) || a[x][y]!='.') continue;
				if (dis[nx][ny]>dis[x][y]){
					dis[nx][ny]=dis[x][y];
					dq.push_front({nx,ny});
				}
			}
			for (int i=max(1,x-k);i<=min(n,x+k);i++){
				for (int j=max(1,y-k);j<=min(m,y+k);j++){
					if (i==x-k && j==y-k) continue;
					if (i==x-k && j==y+k) continue;
					if (i==x+k && j==y-k) continue;
					if (i==x+k && j==y+k) continue;
					if (dis[i][j]>dis[x][y]+1){
						dis[i][j]=dis[x][y]+1;
						dq.push_back({i,j});
					}
				}
			}
		}
	}
	else{
		vector<pair<int,int>> q;
		dis[sx][sy]=0;
		vis[sx][sy]=1;
		q.pb({sx,sy});
		for (int t=0;t<INT_MAX;t++){
			for (int i=0;i<q.size();i++){
				int x=q[i].F,y=q[i].S;
				dis[x][y]=t;
				for (int j=0;j<4;j++){
					int nx=x+mvx[j],ny=y+mvy[j];
					if (vis[nx][ny] || !ok(nx,ny)) continue;
					dis[nx][ny]=t;
					vis[nx][ny]=1;
					q.pb({nx,ny});
				}
			}
			//for (auto u:q) cout<<u.F<<' '<<u.S<<"	";
			//cout<<endl;
			if (vis[ex][ey]) break;
			for (int i=0;i<n+5;i++) for (int j=0;j<m+5;j++) p[i][j]=0;
			for (int i=0;i<q.size();i++){
				int x=q[i].F,y=q[i].S;
				p[max(1,x-k)][max(1,y-k)]++;
				p[max(1,x-k)][min(m,y+k)+1]--;
				p[min(n,x+k)+1][max(1,y-k)]--;
				p[min(n,x+k)+1][min(m,y+k)+1]--;
				if (x-k>=1 && y-k>=1){
					p[x-k][y-k]--;
					p[x-k+1][y-k]++;
					p[x-k][y-k+1]++;
					p[x-k+1][y-k+1]--;
				}
				if (x-k>=1 && y+k<=m){
					p[x-k][y+k]--;
					p[x-k+1][y+k]++;
					p[x-k][y+k+1]++;
					p[x-k+1][y+k+1]--;
				}
				if (x+k<=n && y-k>=1){
					p[x+k][y-k]--;
					p[x+k+1][y-k]++;
					p[x+k][y-k+1]++;
					p[x+k+1][y-k+1]--;
				}
				if (x+k<=n && y+k<=m){
					p[x+k][y+k]--;
					p[x+k+1][y+k]++;
					p[x+k][y+k+1]++;
					p[x+k+1][y+k+1]--;
				}
			}
			for (int i=1;i<=n;i++){
				for (int j=1;j<=m;j++){
					p[i][j]+=p[i-1][j]+p[i][j-1]-p[i-1][j-1];
					if (p[i][j]>0 && !vis[i][j]) q.pb({i,j}),vis[i][j]=1;
					//cout<<p[i][j]<<' ';
				}//cout<<endl;
			}//cout<<endl;
		}
	}
	cout<<dis[ex][ey]<<endl;
	return 0;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
Main.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |    for (int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 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 348 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 3 ms 3164 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1076 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 4 ms 3932 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 7 ms 1884 KB Output is correct
30 Correct 4 ms 2460 KB Output is correct
31 Correct 7 ms 2860 KB Output is correct
32 Correct 9 ms 1884 KB Output is correct
33 Correct 11 ms 1964 KB Output is correct
34 Correct 10 ms 9052 KB Output is correct
35 Correct 9 ms 9264 KB Output is correct
36 Correct 9 ms 1884 KB Output is correct
37 Correct 9 ms 1884 KB Output is correct
38 Correct 7 ms 1884 KB Output is correct
39 Correct 90 ms 15240 KB Output is correct
40 Correct 13 ms 2396 KB Output is correct
41 Correct 12 ms 11100 KB Output is correct
42 Correct 11 ms 2624 KB Output is correct
43 Correct 14 ms 8592 KB Output is correct
44 Correct 43 ms 13772 KB Output is correct
45 Correct 41 ms 15964 KB Output is correct
46 Correct 85 ms 21588 KB Output is correct
47 Correct 91 ms 15196 KB Output is correct
48 Correct 70 ms 15192 KB Output is correct
49 Correct 94 ms 88492 KB Output is correct
50 Correct 88 ms 88312 KB Output is correct
51 Correct 95 ms 15440 KB Output is correct
52 Correct 94 ms 15244 KB Output is correct
53 Correct 78 ms 15192 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 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 1 ms 348 KB Output is correct
8 Correct 0 ms 388 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 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 1 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 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 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 1 ms 348 KB Output is correct
8 Correct 0 ms 388 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 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 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 1 ms 348 KB Output is correct
8 Correct 0 ms 388 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 0 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 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 348 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 3 ms 3164 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1076 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 4 ms 3932 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 7 ms 1884 KB Output is correct
30 Correct 4 ms 2460 KB Output is correct
31 Correct 7 ms 2860 KB Output is correct
32 Correct 9 ms 1884 KB Output is correct
33 Correct 11 ms 1964 KB Output is correct
34 Correct 10 ms 9052 KB Output is correct
35 Correct 9 ms 9264 KB Output is correct
36 Correct 9 ms 1884 KB Output is correct
37 Correct 9 ms 1884 KB Output is correct
38 Correct 7 ms 1884 KB Output is correct
39 Correct 90 ms 15240 KB Output is correct
40 Correct 13 ms 2396 KB Output is correct
41 Correct 12 ms 11100 KB Output is correct
42 Correct 11 ms 2624 KB Output is correct
43 Correct 14 ms 8592 KB Output is correct
44 Correct 43 ms 13772 KB Output is correct
45 Correct 41 ms 15964 KB Output is correct
46 Correct 85 ms 21588 KB Output is correct
47 Correct 91 ms 15196 KB Output is correct
48 Correct 70 ms 15192 KB Output is correct
49 Correct 94 ms 88492 KB Output is correct
50 Correct 88 ms 88312 KB Output is correct
51 Correct 95 ms 15440 KB Output is correct
52 Correct 94 ms 15244 KB Output is correct
53 Correct 78 ms 15192 KB Output is correct
54 Correct 0 ms 344 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 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 388 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 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 348 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 3 ms 3164 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1076 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 4 ms 3932 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 7 ms 1884 KB Output is correct
30 Correct 4 ms 2460 KB Output is correct
31 Correct 7 ms 2860 KB Output is correct
32 Correct 9 ms 1884 KB Output is correct
33 Correct 11 ms 1964 KB Output is correct
34 Correct 10 ms 9052 KB Output is correct
35 Correct 9 ms 9264 KB Output is correct
36 Correct 9 ms 1884 KB Output is correct
37 Correct 9 ms 1884 KB Output is correct
38 Correct 7 ms 1884 KB Output is correct
39 Correct 90 ms 15240 KB Output is correct
40 Correct 13 ms 2396 KB Output is correct
41 Correct 12 ms 11100 KB Output is correct
42 Correct 11 ms 2624 KB Output is correct
43 Correct 14 ms 8592 KB Output is correct
44 Correct 43 ms 13772 KB Output is correct
45 Correct 41 ms 15964 KB Output is correct
46 Correct 85 ms 21588 KB Output is correct
47 Correct 91 ms 15196 KB Output is correct
48 Correct 70 ms 15192 KB Output is correct
49 Correct 94 ms 88492 KB Output is correct
50 Correct 88 ms 88312 KB Output is correct
51 Correct 95 ms 15440 KB Output is correct
52 Correct 94 ms 15244 KB Output is correct
53 Correct 78 ms 15192 KB Output is correct
54 Correct 0 ms 344 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 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 388 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 344 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 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 348 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 3 ms 3164 KB Output is correct
21 Correct 3 ms 1112 KB Output is correct
22 Correct 4 ms 1076 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 4 ms 3932 KB Output is correct
25 Correct 4 ms 3932 KB Output is correct
26 Correct 4 ms 856 KB Output is correct
27 Correct 4 ms 860 KB Output is correct
28 Correct 3 ms 856 KB Output is correct
29 Correct 7 ms 1884 KB Output is correct
30 Correct 4 ms 2460 KB Output is correct
31 Correct 7 ms 2860 KB Output is correct
32 Correct 9 ms 1884 KB Output is correct
33 Correct 11 ms 1964 KB Output is correct
34 Correct 10 ms 9052 KB Output is correct
35 Correct 9 ms 9264 KB Output is correct
36 Correct 9 ms 1884 KB Output is correct
37 Correct 9 ms 1884 KB Output is correct
38 Correct 7 ms 1884 KB Output is correct
39 Correct 90 ms 15240 KB Output is correct
40 Correct 13 ms 2396 KB Output is correct
41 Correct 12 ms 11100 KB Output is correct
42 Correct 11 ms 2624 KB Output is correct
43 Correct 14 ms 8592 KB Output is correct
44 Correct 43 ms 13772 KB Output is correct
45 Correct 41 ms 15964 KB Output is correct
46 Correct 85 ms 21588 KB Output is correct
47 Correct 91 ms 15196 KB Output is correct
48 Correct 70 ms 15192 KB Output is correct
49 Correct 94 ms 88492 KB Output is correct
50 Correct 88 ms 88312 KB Output is correct
51 Correct 95 ms 15440 KB Output is correct
52 Correct 94 ms 15244 KB Output is correct
53 Correct 78 ms 15192 KB Output is correct
54 Correct 0 ms 344 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 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 388 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Incorrect 0 ms 348 KB Output isn't correct
67 Halted 0 ms 0 KB -