Submission #743161

# Submission time Handle Problem Language Result Execution time Memory
743161 2023-05-17T08:28:32 Z zaneyu Maze (JOI23_ho_t3) C++17
0 / 100
2000 ms 329200 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=6e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-4;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
string arr[maxn];
int r,c,n;
int to(int i,int j){
	return i*c+j;
}
bool isin(int x,int y){
	if(x<0 or x>=r or y<0 or y>=c) return false;
	return true;
}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int mxx[maxn],mnx[maxn],mxy[maxn],mny[maxn];
vector<pii> bord[maxn];
bool vis[maxn];
bool bad(int a,int b){
	a=abs(a),b=abs(b);
	if(min(a,b)>=n) return true;
	if(max(a,b)>n) return true;
	return false;
}
int main(){
	cin>>r>>c>>n;
	int sx,sy,a,b;
	cin>>sx>>sy>>a>>b;
	--sx,--sy,--a,--b;
	REP(i,r){
		cin>>arr[i];
	}
	queue<pii> q;
	q.push({sx,sy});
	vector<pii> vv;
	REP(i,r) mxx[i]=-1,mnx[i]=INF;
	REP(i,c) mxy[i]=-1,mny[i]=INF;
	while(sz(q)){
		pii z=q.front();
		MXTO(mxx[z.f],z.s);
		MNTO(mnx[z.f],z.s);
		MXTO(mxy[z.s],z.f);
		MNTO(mny[z.s],z.f);
		q.pop();
		REP(k,4){
			int x=dx[k]+z.f,y=dy[k]+z.s;
			if(!isin(x,y) or arr[x][y]=='#' or vis[to(x,y)]) continue;
			vis[to(x,y)]=1;
			q.push({x,y});
		}
	}
	int ans=0;
	while(!vis[to(a,b)])
	{
		queue<pair<pii,pii>> q;
		REP(i,r){
			if(mxx[i]!=-1) q.push({{i,mxx[i]},{0,0}}),q.push({{i,mnx[i]},{0,0}});
		}
		REP(i,c){
			if(mxy[i]!=-1) q.push({{mxy[i],i},{0,0}}),q.push({{mny[i],i},{0,0}});
		}
		while(sz(q)){
			pii z=q.front().f;
			//cout<<z.f<<' '<<z.s<<'\n';
			MXTO(mxx[z.f],z.s);
			MNTO(mnx[z.f],z.s);
			MXTO(mxy[z.s],z.f);
			MNTO(mny[z.s],z.f);
			pii df=q.front().s;
			q.pop();
			REP(k,4){
				int x=dx[k]+z.f,y=dy[k]+z.s;
				int ndx=df.f+dx[k],ndy=df.s+dy[k];
				if(!isin(x,y) or (arr[x][y]=='#' and bad(ndx,ndy)) or vis[to(x,y)]) continue;
				vis[to(x,y)]=1;
				q.push({{x,y},{ndx,ndy}});
			}
		}
		++ans;
	}
	cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 179 ms 328988 KB Output is correct
2 Correct 183 ms 329024 KB Output is correct
3 Correct 160 ms 328984 KB Output is correct
4 Correct 166 ms 329000 KB Output is correct
5 Correct 154 ms 329092 KB Output is correct
6 Correct 155 ms 329000 KB Output is correct
7 Correct 156 ms 329036 KB Output is correct
8 Correct 178 ms 329016 KB Output is correct
9 Correct 156 ms 328972 KB Output is correct
10 Correct 153 ms 329064 KB Output is correct
11 Correct 159 ms 329060 KB Output is correct
12 Correct 184 ms 329084 KB Output is correct
13 Correct 153 ms 329060 KB Output is correct
14 Correct 174 ms 329136 KB Output is correct
15 Correct 156 ms 329084 KB Output is correct
16 Correct 151 ms 329092 KB Output is correct
17 Execution timed out 2084 ms 329064 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 329088 KB Output is correct
2 Correct 157 ms 329088 KB Output is correct
3 Correct 149 ms 329088 KB Output is correct
4 Correct 150 ms 329116 KB Output is correct
5 Correct 151 ms 329116 KB Output is correct
6 Correct 149 ms 329024 KB Output is correct
7 Correct 168 ms 329000 KB Output is correct
8 Correct 167 ms 329100 KB Output is correct
9 Correct 148 ms 329180 KB Output is correct
10 Correct 157 ms 329100 KB Output is correct
11 Correct 147 ms 329080 KB Output is correct
12 Correct 148 ms 329036 KB Output is correct
13 Correct 151 ms 329092 KB Output is correct
14 Correct 146 ms 329092 KB Output is correct
15 Correct 143 ms 328988 KB Output is correct
16 Correct 180 ms 329200 KB Output is correct
17 Correct 147 ms 329028 KB Output is correct
18 Correct 146 ms 328996 KB Output is correct
19 Correct 148 ms 329068 KB Output is correct
20 Correct 147 ms 329040 KB Output is correct
21 Correct 173 ms 329064 KB Output is correct
22 Correct 147 ms 329092 KB Output is correct
23 Correct 148 ms 329084 KB Output is correct
24 Correct 158 ms 329024 KB Output is correct
25 Correct 143 ms 329032 KB Output is correct
26 Correct 146 ms 329024 KB Output is correct
27 Correct 161 ms 329084 KB Output is correct
28 Correct 152 ms 329012 KB Output is correct
29 Correct 160 ms 329020 KB Output is correct
30 Correct 148 ms 329036 KB Output is correct
31 Execution timed out 2076 ms 329032 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 329152 KB Output is correct
2 Correct 155 ms 329148 KB Output is correct
3 Correct 147 ms 329056 KB Output is correct
4 Correct 148 ms 329048 KB Output is correct
5 Correct 145 ms 329044 KB Output is correct
6 Correct 166 ms 329044 KB Output is correct
7 Correct 158 ms 329028 KB Output is correct
8 Correct 149 ms 329124 KB Output is correct
9 Correct 143 ms 329164 KB Output is correct
10 Correct 144 ms 329060 KB Output is correct
11 Correct 150 ms 329076 KB Output is correct
12 Correct 161 ms 328988 KB Output is correct
13 Correct 147 ms 329028 KB Output is correct
14 Correct 149 ms 329004 KB Output is correct
15 Correct 148 ms 329060 KB Output is correct
16 Correct 167 ms 329092 KB Output is correct
17 Correct 148 ms 329084 KB Output is correct
18 Correct 157 ms 328964 KB Output is correct
19 Correct 148 ms 329012 KB Output is correct
20 Correct 144 ms 329024 KB Output is correct
21 Correct 151 ms 329044 KB Output is correct
22 Correct 153 ms 329008 KB Output is correct
23 Execution timed out 2094 ms 329044 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 329088 KB Output is correct
2 Correct 157 ms 329088 KB Output is correct
3 Correct 149 ms 329088 KB Output is correct
4 Correct 150 ms 329116 KB Output is correct
5 Correct 151 ms 329116 KB Output is correct
6 Correct 149 ms 329024 KB Output is correct
7 Correct 168 ms 329000 KB Output is correct
8 Correct 167 ms 329100 KB Output is correct
9 Correct 148 ms 329180 KB Output is correct
10 Correct 157 ms 329100 KB Output is correct
11 Correct 147 ms 329080 KB Output is correct
12 Correct 148 ms 329036 KB Output is correct
13 Correct 151 ms 329092 KB Output is correct
14 Correct 146 ms 329092 KB Output is correct
15 Correct 143 ms 328988 KB Output is correct
16 Correct 180 ms 329200 KB Output is correct
17 Correct 147 ms 329028 KB Output is correct
18 Correct 146 ms 328996 KB Output is correct
19 Correct 148 ms 329068 KB Output is correct
20 Correct 147 ms 329040 KB Output is correct
21 Correct 173 ms 329064 KB Output is correct
22 Correct 147 ms 329092 KB Output is correct
23 Correct 148 ms 329084 KB Output is correct
24 Correct 158 ms 329024 KB Output is correct
25 Correct 143 ms 329032 KB Output is correct
26 Correct 146 ms 329024 KB Output is correct
27 Correct 161 ms 329084 KB Output is correct
28 Correct 152 ms 329012 KB Output is correct
29 Correct 160 ms 329020 KB Output is correct
30 Correct 148 ms 329036 KB Output is correct
31 Execution timed out 2076 ms 329032 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 329088 KB Output is correct
2 Correct 157 ms 329088 KB Output is correct
3 Correct 149 ms 329088 KB Output is correct
4 Correct 150 ms 329116 KB Output is correct
5 Correct 151 ms 329116 KB Output is correct
6 Correct 149 ms 329024 KB Output is correct
7 Correct 168 ms 329000 KB Output is correct
8 Correct 167 ms 329100 KB Output is correct
9 Correct 148 ms 329180 KB Output is correct
10 Correct 157 ms 329100 KB Output is correct
11 Correct 147 ms 329080 KB Output is correct
12 Correct 148 ms 329036 KB Output is correct
13 Correct 151 ms 329092 KB Output is correct
14 Correct 146 ms 329092 KB Output is correct
15 Correct 143 ms 328988 KB Output is correct
16 Correct 180 ms 329200 KB Output is correct
17 Correct 147 ms 329028 KB Output is correct
18 Correct 146 ms 328996 KB Output is correct
19 Correct 148 ms 329068 KB Output is correct
20 Correct 147 ms 329040 KB Output is correct
21 Correct 173 ms 329064 KB Output is correct
22 Correct 147 ms 329092 KB Output is correct
23 Correct 148 ms 329084 KB Output is correct
24 Correct 158 ms 329024 KB Output is correct
25 Correct 143 ms 329032 KB Output is correct
26 Correct 146 ms 329024 KB Output is correct
27 Correct 161 ms 329084 KB Output is correct
28 Correct 152 ms 329012 KB Output is correct
29 Correct 160 ms 329020 KB Output is correct
30 Correct 148 ms 329036 KB Output is correct
31 Execution timed out 2076 ms 329032 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 179 ms 328988 KB Output is correct
2 Correct 183 ms 329024 KB Output is correct
3 Correct 160 ms 328984 KB Output is correct
4 Correct 166 ms 329000 KB Output is correct
5 Correct 154 ms 329092 KB Output is correct
6 Correct 155 ms 329000 KB Output is correct
7 Correct 156 ms 329036 KB Output is correct
8 Correct 178 ms 329016 KB Output is correct
9 Correct 156 ms 328972 KB Output is correct
10 Correct 153 ms 329064 KB Output is correct
11 Correct 159 ms 329060 KB Output is correct
12 Correct 184 ms 329084 KB Output is correct
13 Correct 153 ms 329060 KB Output is correct
14 Correct 174 ms 329136 KB Output is correct
15 Correct 156 ms 329084 KB Output is correct
16 Correct 151 ms 329092 KB Output is correct
17 Execution timed out 2084 ms 329064 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 179 ms 328988 KB Output is correct
2 Correct 183 ms 329024 KB Output is correct
3 Correct 160 ms 328984 KB Output is correct
4 Correct 166 ms 329000 KB Output is correct
5 Correct 154 ms 329092 KB Output is correct
6 Correct 155 ms 329000 KB Output is correct
7 Correct 156 ms 329036 KB Output is correct
8 Correct 178 ms 329016 KB Output is correct
9 Correct 156 ms 328972 KB Output is correct
10 Correct 153 ms 329064 KB Output is correct
11 Correct 159 ms 329060 KB Output is correct
12 Correct 184 ms 329084 KB Output is correct
13 Correct 153 ms 329060 KB Output is correct
14 Correct 174 ms 329136 KB Output is correct
15 Correct 156 ms 329084 KB Output is correct
16 Correct 151 ms 329092 KB Output is correct
17 Execution timed out 2084 ms 329064 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 179 ms 328988 KB Output is correct
2 Correct 183 ms 329024 KB Output is correct
3 Correct 160 ms 328984 KB Output is correct
4 Correct 166 ms 329000 KB Output is correct
5 Correct 154 ms 329092 KB Output is correct
6 Correct 155 ms 329000 KB Output is correct
7 Correct 156 ms 329036 KB Output is correct
8 Correct 178 ms 329016 KB Output is correct
9 Correct 156 ms 328972 KB Output is correct
10 Correct 153 ms 329064 KB Output is correct
11 Correct 159 ms 329060 KB Output is correct
12 Correct 184 ms 329084 KB Output is correct
13 Correct 153 ms 329060 KB Output is correct
14 Correct 174 ms 329136 KB Output is correct
15 Correct 156 ms 329084 KB Output is correct
16 Correct 151 ms 329092 KB Output is correct
17 Execution timed out 2084 ms 329064 KB Time limit exceeded
18 Halted 0 ms 0 KB -