답안 #1046688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046688 2024-08-06T20:26:20 Z 1L1YA Maze (JOI23_ho_t3) C++17
8 / 100
133 ms 350180 KB
//1L1YA
 
#include<bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
typedef long long       ll;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;
 
#define Pb              push_back
#define F               first
#define S               second
#define endl            '\n'
#define sep             ' '
#define all(x)          x.begin(),x.end()
#define al(x,n)         x+1,x+n+1
#define SZ(x)           ((int)x.size())
#define lc              (id<<1)
#define rc              (lc|1)
#define mid             (l+r>>1)
#define dokme(x)        cout << x << endl, exit(0)
#define sik(x)          cout << x << endl;continue;
#define FastIO          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=6e6+11;
const int lg=23;
 
int n,m,k,xs,ys,xt,yt,x[4]={1,-1,0,0},y[4]={0,0,1,-1};
vector<int> d[N];
string s[N];
 
void bfs(){
	queue<pii> Q;
	deque<pair<pii,pii>> QQ;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			d[i][j]=inf;
	d[xs][ys]=0;
	QQ.Pb({{xs,ys},{0,0}});
	while(!QQ.empty()){
		int p=QQ.front().F.F,q=QQ.front().F.S;QQ.pop_front();
		Q.push({p,q});
		for(int i=0;i<4;i++)
			if(p+x[i] && p+x[i]<=n && q+y[i] && q+y[i]<=m && d[p+x[i]][q+y[i]] && s[p+x[i]][q+y[i]]=='.'){
				d[p+x[i]][q+y[i]]=0;
				QQ.Pb({{p+x[i],q+y[i]},{0,0}});
			}
	}
	while(!Q.empty()){
		while(!Q.empty()){
			int p=Q.front().F,q=Q.front().S;Q.pop();
			for(int i=0;i<4;i++)
				if(p+x[i] && p+x[i]<=n && q+y[i] && q+y[i]<=m && d[p][q]+1<d[p+x[i]][q+y[i]]){
					d[p+x[i]][q+y[i]]=d[p][q]+1;
					QQ.Pb({{p+x[i],q+y[i]},{abs(x[i]),abs(y[i])}});
				}
		}
		while(!QQ.empty()){
			int p=QQ.front().F.F,q=QQ.front().F.S;
			pii val=QQ.front().S;
			QQ.pop_front();
			Q.push({p,q});
			for(int i=0;i<4;i++)
				if(p+x[i] && p+x[i]<=n && q+y[i] && q+y[i]<=m && d[p][q]<d[p+x[i]][q+y[i]] && ((val.F+abs(x[i])<=k && val.S+abs(y[i])<=k && (val.F+abs(x[i])<k || val.S+abs(y[i])<k)))){
					d[p+x[i]][q+y[i]]=d[p][q];
					QQ.push_front({{p+x[i],q+y[i]},{val.F+abs(x[i]),val.S+abs(y[i])}});
				}
				else if(p+x[i] && p+x[i]<=n && q+y[i] && q+y[i]<=m && d[p][q]<d[p+x[i]][q+y[i]] && s[p+x[i]][q+y[i]]=='.'){
					d[p+x[i]][q+y[i]]=d[p][q];
					QQ.Pb({{p+x[i],q+y[i]},{val.F+abs(x[i]),val.S+abs(y[i])}});
				}
		}
	}
}
 
int main(){
	FastIO
 
	cin >> n >> m >> k >> xs >> ys >> xt >> yt;
	for(int i=1;i<=n;i++){
		cin >> s[i];
		s[i]='#'+s[i];
		d[i].resize(m+1);
	}
	bfs();
	//for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cout << d[i][j] << sep;cout << endl;}
	cout << d[xt][yt] << endl;
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 329040 KB Output is correct
2 Correct 45 ms 329200 KB Output is correct
3 Correct 44 ms 329052 KB Output is correct
4 Correct 51 ms 329140 KB Output is correct
5 Correct 44 ms 329052 KB Output is correct
6 Correct 45 ms 329208 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 45 ms 329136 KB Output is correct
9 Correct 46 ms 329048 KB Output is correct
10 Correct 44 ms 329040 KB Output is correct
11 Correct 44 ms 329040 KB Output is correct
12 Correct 45 ms 329032 KB Output is correct
13 Correct 44 ms 329044 KB Output is correct
14 Correct 45 ms 329044 KB Output is correct
15 Correct 43 ms 329040 KB Output is correct
16 Correct 44 ms 329048 KB Output is correct
17 Correct 43 ms 329052 KB Output is correct
18 Correct 45 ms 329048 KB Output is correct
19 Correct 47 ms 329564 KB Output is correct
20 Correct 46 ms 329296 KB Output is correct
21 Correct 46 ms 330064 KB Output is correct
22 Correct 47 ms 329556 KB Output is correct
23 Correct 45 ms 329576 KB Output is correct
24 Correct 45 ms 329552 KB Output is correct
25 Correct 49 ms 329544 KB Output is correct
26 Correct 54 ms 329552 KB Output is correct
27 Correct 48 ms 329564 KB Output is correct
28 Correct 46 ms 329588 KB Output is correct
29 Correct 52 ms 330116 KB Output is correct
30 Correct 48 ms 329556 KB Output is correct
31 Correct 47 ms 331224 KB Output is correct
32 Correct 56 ms 330008 KB Output is correct
33 Correct 49 ms 330068 KB Output is correct
34 Correct 56 ms 330056 KB Output is correct
35 Correct 48 ms 330056 KB Output is correct
36 Correct 53 ms 330064 KB Output is correct
37 Correct 52 ms 330068 KB Output is correct
38 Correct 50 ms 330056 KB Output is correct
39 Correct 114 ms 337884 KB Output is correct
40 Correct 53 ms 330092 KB Output is correct
41 Correct 49 ms 330280 KB Output is correct
42 Correct 54 ms 330396 KB Output is correct
43 Correct 53 ms 330580 KB Output is correct
44 Correct 82 ms 333524 KB Output is correct
45 Correct 101 ms 334016 KB Output is correct
46 Correct 94 ms 350180 KB Output is correct
47 Correct 124 ms 338000 KB Output is correct
48 Correct 107 ms 338004 KB Output is correct
49 Correct 82 ms 337976 KB Output is correct
50 Correct 85 ms 337976 KB Output is correct
51 Correct 132 ms 338596 KB Output is correct
52 Correct 133 ms 338076 KB Output is correct
53 Correct 120 ms 338004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 329052 KB Output is correct
2 Correct 44 ms 329072 KB Output is correct
3 Correct 44 ms 329044 KB Output is correct
4 Correct 44 ms 328964 KB Output is correct
5 Correct 44 ms 329048 KB Output is correct
6 Correct 50 ms 329044 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 43 ms 329048 KB Output is correct
9 Correct 44 ms 329052 KB Output is correct
10 Correct 46 ms 329044 KB Output is correct
11 Correct 49 ms 329052 KB Output is correct
12 Correct 44 ms 329044 KB Output is correct
13 Correct 45 ms 329228 KB Output is correct
14 Correct 44 ms 329040 KB Output is correct
15 Correct 45 ms 329052 KB Output is correct
16 Correct 43 ms 329052 KB Output is correct
17 Correct 44 ms 329052 KB Output is correct
18 Correct 46 ms 329044 KB Output is correct
19 Correct 43 ms 329040 KB Output is correct
20 Incorrect 46 ms 329040 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 329188 KB Output is correct
2 Correct 47 ms 329044 KB Output is correct
3 Correct 49 ms 329052 KB Output is correct
4 Correct 44 ms 329044 KB Output is correct
5 Correct 44 ms 329204 KB Output is correct
6 Correct 43 ms 329044 KB Output is correct
7 Correct 43 ms 329200 KB Output is correct
8 Correct 46 ms 329040 KB Output is correct
9 Correct 44 ms 329228 KB Output is correct
10 Correct 45 ms 329044 KB Output is correct
11 Correct 47 ms 329176 KB Output is correct
12 Correct 47 ms 329044 KB Output is correct
13 Correct 44 ms 329040 KB Output is correct
14 Correct 44 ms 329044 KB Output is correct
15 Correct 44 ms 329044 KB Output is correct
16 Correct 50 ms 329048 KB Output is correct
17 Correct 44 ms 329048 KB Output is correct
18 Correct 43 ms 329184 KB Output is correct
19 Correct 47 ms 329052 KB Output is correct
20 Correct 49 ms 329052 KB Output is correct
21 Correct 48 ms 329132 KB Output is correct
22 Correct 44 ms 329080 KB Output is correct
23 Correct 44 ms 329040 KB Output is correct
24 Correct 50 ms 329044 KB Output is correct
25 Incorrect 45 ms 329308 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 329052 KB Output is correct
2 Correct 44 ms 329072 KB Output is correct
3 Correct 44 ms 329044 KB Output is correct
4 Correct 44 ms 328964 KB Output is correct
5 Correct 44 ms 329048 KB Output is correct
6 Correct 50 ms 329044 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 43 ms 329048 KB Output is correct
9 Correct 44 ms 329052 KB Output is correct
10 Correct 46 ms 329044 KB Output is correct
11 Correct 49 ms 329052 KB Output is correct
12 Correct 44 ms 329044 KB Output is correct
13 Correct 45 ms 329228 KB Output is correct
14 Correct 44 ms 329040 KB Output is correct
15 Correct 45 ms 329052 KB Output is correct
16 Correct 43 ms 329052 KB Output is correct
17 Correct 44 ms 329052 KB Output is correct
18 Correct 46 ms 329044 KB Output is correct
19 Correct 43 ms 329040 KB Output is correct
20 Incorrect 46 ms 329040 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 329052 KB Output is correct
2 Correct 44 ms 329072 KB Output is correct
3 Correct 44 ms 329044 KB Output is correct
4 Correct 44 ms 328964 KB Output is correct
5 Correct 44 ms 329048 KB Output is correct
6 Correct 50 ms 329044 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 43 ms 329048 KB Output is correct
9 Correct 44 ms 329052 KB Output is correct
10 Correct 46 ms 329044 KB Output is correct
11 Correct 49 ms 329052 KB Output is correct
12 Correct 44 ms 329044 KB Output is correct
13 Correct 45 ms 329228 KB Output is correct
14 Correct 44 ms 329040 KB Output is correct
15 Correct 45 ms 329052 KB Output is correct
16 Correct 43 ms 329052 KB Output is correct
17 Correct 44 ms 329052 KB Output is correct
18 Correct 46 ms 329044 KB Output is correct
19 Correct 43 ms 329040 KB Output is correct
20 Incorrect 46 ms 329040 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 329040 KB Output is correct
2 Correct 45 ms 329200 KB Output is correct
3 Correct 44 ms 329052 KB Output is correct
4 Correct 51 ms 329140 KB Output is correct
5 Correct 44 ms 329052 KB Output is correct
6 Correct 45 ms 329208 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 45 ms 329136 KB Output is correct
9 Correct 46 ms 329048 KB Output is correct
10 Correct 44 ms 329040 KB Output is correct
11 Correct 44 ms 329040 KB Output is correct
12 Correct 45 ms 329032 KB Output is correct
13 Correct 44 ms 329044 KB Output is correct
14 Correct 45 ms 329044 KB Output is correct
15 Correct 43 ms 329040 KB Output is correct
16 Correct 44 ms 329048 KB Output is correct
17 Correct 43 ms 329052 KB Output is correct
18 Correct 45 ms 329048 KB Output is correct
19 Correct 47 ms 329564 KB Output is correct
20 Correct 46 ms 329296 KB Output is correct
21 Correct 46 ms 330064 KB Output is correct
22 Correct 47 ms 329556 KB Output is correct
23 Correct 45 ms 329576 KB Output is correct
24 Correct 45 ms 329552 KB Output is correct
25 Correct 49 ms 329544 KB Output is correct
26 Correct 54 ms 329552 KB Output is correct
27 Correct 48 ms 329564 KB Output is correct
28 Correct 46 ms 329588 KB Output is correct
29 Correct 52 ms 330116 KB Output is correct
30 Correct 48 ms 329556 KB Output is correct
31 Correct 47 ms 331224 KB Output is correct
32 Correct 56 ms 330008 KB Output is correct
33 Correct 49 ms 330068 KB Output is correct
34 Correct 56 ms 330056 KB Output is correct
35 Correct 48 ms 330056 KB Output is correct
36 Correct 53 ms 330064 KB Output is correct
37 Correct 52 ms 330068 KB Output is correct
38 Correct 50 ms 330056 KB Output is correct
39 Correct 114 ms 337884 KB Output is correct
40 Correct 53 ms 330092 KB Output is correct
41 Correct 49 ms 330280 KB Output is correct
42 Correct 54 ms 330396 KB Output is correct
43 Correct 53 ms 330580 KB Output is correct
44 Correct 82 ms 333524 KB Output is correct
45 Correct 101 ms 334016 KB Output is correct
46 Correct 94 ms 350180 KB Output is correct
47 Correct 124 ms 338000 KB Output is correct
48 Correct 107 ms 338004 KB Output is correct
49 Correct 82 ms 337976 KB Output is correct
50 Correct 85 ms 337976 KB Output is correct
51 Correct 132 ms 338596 KB Output is correct
52 Correct 133 ms 338076 KB Output is correct
53 Correct 120 ms 338004 KB Output is correct
54 Correct 44 ms 329052 KB Output is correct
55 Correct 44 ms 329072 KB Output is correct
56 Correct 44 ms 329044 KB Output is correct
57 Correct 44 ms 328964 KB Output is correct
58 Correct 44 ms 329048 KB Output is correct
59 Correct 50 ms 329044 KB Output is correct
60 Correct 43 ms 329044 KB Output is correct
61 Correct 43 ms 329048 KB Output is correct
62 Correct 44 ms 329052 KB Output is correct
63 Correct 46 ms 329044 KB Output is correct
64 Correct 49 ms 329052 KB Output is correct
65 Correct 44 ms 329044 KB Output is correct
66 Correct 45 ms 329228 KB Output is correct
67 Correct 44 ms 329040 KB Output is correct
68 Correct 45 ms 329052 KB Output is correct
69 Correct 43 ms 329052 KB Output is correct
70 Correct 44 ms 329052 KB Output is correct
71 Correct 46 ms 329044 KB Output is correct
72 Correct 43 ms 329040 KB Output is correct
73 Incorrect 46 ms 329040 KB Output isn't correct
74 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 329040 KB Output is correct
2 Correct 45 ms 329200 KB Output is correct
3 Correct 44 ms 329052 KB Output is correct
4 Correct 51 ms 329140 KB Output is correct
5 Correct 44 ms 329052 KB Output is correct
6 Correct 45 ms 329208 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 45 ms 329136 KB Output is correct
9 Correct 46 ms 329048 KB Output is correct
10 Correct 44 ms 329040 KB Output is correct
11 Correct 44 ms 329040 KB Output is correct
12 Correct 45 ms 329032 KB Output is correct
13 Correct 44 ms 329044 KB Output is correct
14 Correct 45 ms 329044 KB Output is correct
15 Correct 43 ms 329040 KB Output is correct
16 Correct 44 ms 329048 KB Output is correct
17 Correct 43 ms 329052 KB Output is correct
18 Correct 45 ms 329048 KB Output is correct
19 Correct 47 ms 329564 KB Output is correct
20 Correct 46 ms 329296 KB Output is correct
21 Correct 46 ms 330064 KB Output is correct
22 Correct 47 ms 329556 KB Output is correct
23 Correct 45 ms 329576 KB Output is correct
24 Correct 45 ms 329552 KB Output is correct
25 Correct 49 ms 329544 KB Output is correct
26 Correct 54 ms 329552 KB Output is correct
27 Correct 48 ms 329564 KB Output is correct
28 Correct 46 ms 329588 KB Output is correct
29 Correct 52 ms 330116 KB Output is correct
30 Correct 48 ms 329556 KB Output is correct
31 Correct 47 ms 331224 KB Output is correct
32 Correct 56 ms 330008 KB Output is correct
33 Correct 49 ms 330068 KB Output is correct
34 Correct 56 ms 330056 KB Output is correct
35 Correct 48 ms 330056 KB Output is correct
36 Correct 53 ms 330064 KB Output is correct
37 Correct 52 ms 330068 KB Output is correct
38 Correct 50 ms 330056 KB Output is correct
39 Correct 114 ms 337884 KB Output is correct
40 Correct 53 ms 330092 KB Output is correct
41 Correct 49 ms 330280 KB Output is correct
42 Correct 54 ms 330396 KB Output is correct
43 Correct 53 ms 330580 KB Output is correct
44 Correct 82 ms 333524 KB Output is correct
45 Correct 101 ms 334016 KB Output is correct
46 Correct 94 ms 350180 KB Output is correct
47 Correct 124 ms 338000 KB Output is correct
48 Correct 107 ms 338004 KB Output is correct
49 Correct 82 ms 337976 KB Output is correct
50 Correct 85 ms 337976 KB Output is correct
51 Correct 132 ms 338596 KB Output is correct
52 Correct 133 ms 338076 KB Output is correct
53 Correct 120 ms 338004 KB Output is correct
54 Correct 44 ms 329052 KB Output is correct
55 Correct 44 ms 329072 KB Output is correct
56 Correct 44 ms 329044 KB Output is correct
57 Correct 44 ms 328964 KB Output is correct
58 Correct 44 ms 329048 KB Output is correct
59 Correct 50 ms 329044 KB Output is correct
60 Correct 43 ms 329044 KB Output is correct
61 Correct 43 ms 329048 KB Output is correct
62 Correct 44 ms 329052 KB Output is correct
63 Correct 46 ms 329044 KB Output is correct
64 Correct 49 ms 329052 KB Output is correct
65 Correct 44 ms 329044 KB Output is correct
66 Correct 45 ms 329228 KB Output is correct
67 Correct 44 ms 329040 KB Output is correct
68 Correct 45 ms 329052 KB Output is correct
69 Correct 43 ms 329052 KB Output is correct
70 Correct 44 ms 329052 KB Output is correct
71 Correct 46 ms 329044 KB Output is correct
72 Correct 43 ms 329040 KB Output is correct
73 Incorrect 46 ms 329040 KB Output isn't correct
74 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 329040 KB Output is correct
2 Correct 45 ms 329200 KB Output is correct
3 Correct 44 ms 329052 KB Output is correct
4 Correct 51 ms 329140 KB Output is correct
5 Correct 44 ms 329052 KB Output is correct
6 Correct 45 ms 329208 KB Output is correct
7 Correct 43 ms 329044 KB Output is correct
8 Correct 45 ms 329136 KB Output is correct
9 Correct 46 ms 329048 KB Output is correct
10 Correct 44 ms 329040 KB Output is correct
11 Correct 44 ms 329040 KB Output is correct
12 Correct 45 ms 329032 KB Output is correct
13 Correct 44 ms 329044 KB Output is correct
14 Correct 45 ms 329044 KB Output is correct
15 Correct 43 ms 329040 KB Output is correct
16 Correct 44 ms 329048 KB Output is correct
17 Correct 43 ms 329052 KB Output is correct
18 Correct 45 ms 329048 KB Output is correct
19 Correct 47 ms 329564 KB Output is correct
20 Correct 46 ms 329296 KB Output is correct
21 Correct 46 ms 330064 KB Output is correct
22 Correct 47 ms 329556 KB Output is correct
23 Correct 45 ms 329576 KB Output is correct
24 Correct 45 ms 329552 KB Output is correct
25 Correct 49 ms 329544 KB Output is correct
26 Correct 54 ms 329552 KB Output is correct
27 Correct 48 ms 329564 KB Output is correct
28 Correct 46 ms 329588 KB Output is correct
29 Correct 52 ms 330116 KB Output is correct
30 Correct 48 ms 329556 KB Output is correct
31 Correct 47 ms 331224 KB Output is correct
32 Correct 56 ms 330008 KB Output is correct
33 Correct 49 ms 330068 KB Output is correct
34 Correct 56 ms 330056 KB Output is correct
35 Correct 48 ms 330056 KB Output is correct
36 Correct 53 ms 330064 KB Output is correct
37 Correct 52 ms 330068 KB Output is correct
38 Correct 50 ms 330056 KB Output is correct
39 Correct 114 ms 337884 KB Output is correct
40 Correct 53 ms 330092 KB Output is correct
41 Correct 49 ms 330280 KB Output is correct
42 Correct 54 ms 330396 KB Output is correct
43 Correct 53 ms 330580 KB Output is correct
44 Correct 82 ms 333524 KB Output is correct
45 Correct 101 ms 334016 KB Output is correct
46 Correct 94 ms 350180 KB Output is correct
47 Correct 124 ms 338000 KB Output is correct
48 Correct 107 ms 338004 KB Output is correct
49 Correct 82 ms 337976 KB Output is correct
50 Correct 85 ms 337976 KB Output is correct
51 Correct 132 ms 338596 KB Output is correct
52 Correct 133 ms 338076 KB Output is correct
53 Correct 120 ms 338004 KB Output is correct
54 Correct 44 ms 329052 KB Output is correct
55 Correct 44 ms 329072 KB Output is correct
56 Correct 44 ms 329044 KB Output is correct
57 Correct 44 ms 328964 KB Output is correct
58 Correct 44 ms 329048 KB Output is correct
59 Correct 50 ms 329044 KB Output is correct
60 Correct 43 ms 329044 KB Output is correct
61 Correct 43 ms 329048 KB Output is correct
62 Correct 44 ms 329052 KB Output is correct
63 Correct 46 ms 329044 KB Output is correct
64 Correct 49 ms 329052 KB Output is correct
65 Correct 44 ms 329044 KB Output is correct
66 Correct 45 ms 329228 KB Output is correct
67 Correct 44 ms 329040 KB Output is correct
68 Correct 45 ms 329052 KB Output is correct
69 Correct 43 ms 329052 KB Output is correct
70 Correct 44 ms 329052 KB Output is correct
71 Correct 46 ms 329044 KB Output is correct
72 Correct 43 ms 329040 KB Output is correct
73 Incorrect 46 ms 329040 KB Output isn't correct
74 Halted 0 ms 0 KB -