답안 #743175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743175 2023-05-17T08:36:26 Z zaneyu Maze (JOI23_ho_t3) C++17
0 / 100
2000 ms 329248 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;
	vector<int> hx,hy;
	while(sz(q)){
		pii z=q.front();
		if(mxx[z.f]==-1) hx.pb(z.f);
		if(mxy[z.s]==-1) hy.pb(z.s);
		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;
		for(int i:hx){
			if(mxx[i]!=-1) q.push({{i,mxx[i]},{0,0}}),q.push({{i,mnx[i]},{0,0}});
		}
		for(int i:hy){
			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;
			if(mxx[z.f]==-1) hx.pb(z.f);
			if(mxy[z.s]==-1) hy.pb(z.s);
			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';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 329036 KB Output is correct
2 Correct 144 ms 329064 KB Output is correct
3 Correct 160 ms 329060 KB Output is correct
4 Correct 151 ms 329196 KB Output is correct
5 Correct 151 ms 329072 KB Output is correct
6 Correct 163 ms 329000 KB Output is correct
7 Correct 149 ms 329016 KB Output is correct
8 Correct 162 ms 329248 KB Output is correct
9 Correct 151 ms 329044 KB Output is correct
10 Correct 153 ms 329092 KB Output is correct
11 Correct 164 ms 329092 KB Output is correct
12 Correct 149 ms 328980 KB Output is correct
13 Correct 148 ms 329004 KB Output is correct
14 Correct 157 ms 329096 KB Output is correct
15 Correct 149 ms 329200 KB Output is correct
16 Correct 150 ms 329156 KB Output is correct
17 Execution timed out 2078 ms 328968 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 329024 KB Output is correct
2 Correct 152 ms 329060 KB Output is correct
3 Correct 176 ms 329168 KB Output is correct
4 Correct 158 ms 329076 KB Output is correct
5 Correct 159 ms 329084 KB Output is correct
6 Correct 152 ms 329052 KB Output is correct
7 Correct 147 ms 329036 KB Output is correct
8 Correct 145 ms 329048 KB Output is correct
9 Correct 152 ms 329036 KB Output is correct
10 Correct 155 ms 329032 KB Output is correct
11 Correct 168 ms 329060 KB Output is correct
12 Correct 153 ms 329088 KB Output is correct
13 Correct 172 ms 329048 KB Output is correct
14 Correct 154 ms 329040 KB Output is correct
15 Correct 163 ms 329028 KB Output is correct
16 Correct 162 ms 329068 KB Output is correct
17 Correct 146 ms 329196 KB Output is correct
18 Correct 147 ms 329024 KB Output is correct
19 Correct 168 ms 329028 KB Output is correct
20 Correct 174 ms 329144 KB Output is correct
21 Correct 157 ms 329004 KB Output is correct
22 Correct 147 ms 329004 KB Output is correct
23 Correct 146 ms 329072 KB Output is correct
24 Correct 151 ms 329056 KB Output is correct
25 Correct 154 ms 329000 KB Output is correct
26 Correct 149 ms 328976 KB Output is correct
27 Correct 153 ms 328996 KB Output is correct
28 Correct 163 ms 329008 KB Output is correct
29 Correct 156 ms 329036 KB Output is correct
30 Correct 169 ms 328968 KB Output is correct
31 Execution timed out 2094 ms 329136 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 329092 KB Output is correct
2 Correct 160 ms 329068 KB Output is correct
3 Correct 149 ms 328976 KB Output is correct
4 Correct 150 ms 328988 KB Output is correct
5 Correct 158 ms 329068 KB Output is correct
6 Correct 158 ms 329056 KB Output is correct
7 Correct 147 ms 328996 KB Output is correct
8 Correct 162 ms 329004 KB Output is correct
9 Correct 176 ms 329096 KB Output is correct
10 Correct 160 ms 328972 KB Output is correct
11 Correct 147 ms 329092 KB Output is correct
12 Correct 156 ms 329060 KB Output is correct
13 Correct 158 ms 329084 KB Output is correct
14 Correct 162 ms 329088 KB Output is correct
15 Correct 146 ms 329108 KB Output is correct
16 Correct 158 ms 329036 KB Output is correct
17 Correct 148 ms 329084 KB Output is correct
18 Correct 145 ms 329044 KB Output is correct
19 Correct 166 ms 328972 KB Output is correct
20 Correct 152 ms 329092 KB Output is correct
21 Correct 150 ms 329016 KB Output is correct
22 Correct 157 ms 329060 KB Output is correct
23 Execution timed out 2098 ms 328988 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 329024 KB Output is correct
2 Correct 152 ms 329060 KB Output is correct
3 Correct 176 ms 329168 KB Output is correct
4 Correct 158 ms 329076 KB Output is correct
5 Correct 159 ms 329084 KB Output is correct
6 Correct 152 ms 329052 KB Output is correct
7 Correct 147 ms 329036 KB Output is correct
8 Correct 145 ms 329048 KB Output is correct
9 Correct 152 ms 329036 KB Output is correct
10 Correct 155 ms 329032 KB Output is correct
11 Correct 168 ms 329060 KB Output is correct
12 Correct 153 ms 329088 KB Output is correct
13 Correct 172 ms 329048 KB Output is correct
14 Correct 154 ms 329040 KB Output is correct
15 Correct 163 ms 329028 KB Output is correct
16 Correct 162 ms 329068 KB Output is correct
17 Correct 146 ms 329196 KB Output is correct
18 Correct 147 ms 329024 KB Output is correct
19 Correct 168 ms 329028 KB Output is correct
20 Correct 174 ms 329144 KB Output is correct
21 Correct 157 ms 329004 KB Output is correct
22 Correct 147 ms 329004 KB Output is correct
23 Correct 146 ms 329072 KB Output is correct
24 Correct 151 ms 329056 KB Output is correct
25 Correct 154 ms 329000 KB Output is correct
26 Correct 149 ms 328976 KB Output is correct
27 Correct 153 ms 328996 KB Output is correct
28 Correct 163 ms 329008 KB Output is correct
29 Correct 156 ms 329036 KB Output is correct
30 Correct 169 ms 328968 KB Output is correct
31 Execution timed out 2094 ms 329136 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 329024 KB Output is correct
2 Correct 152 ms 329060 KB Output is correct
3 Correct 176 ms 329168 KB Output is correct
4 Correct 158 ms 329076 KB Output is correct
5 Correct 159 ms 329084 KB Output is correct
6 Correct 152 ms 329052 KB Output is correct
7 Correct 147 ms 329036 KB Output is correct
8 Correct 145 ms 329048 KB Output is correct
9 Correct 152 ms 329036 KB Output is correct
10 Correct 155 ms 329032 KB Output is correct
11 Correct 168 ms 329060 KB Output is correct
12 Correct 153 ms 329088 KB Output is correct
13 Correct 172 ms 329048 KB Output is correct
14 Correct 154 ms 329040 KB Output is correct
15 Correct 163 ms 329028 KB Output is correct
16 Correct 162 ms 329068 KB Output is correct
17 Correct 146 ms 329196 KB Output is correct
18 Correct 147 ms 329024 KB Output is correct
19 Correct 168 ms 329028 KB Output is correct
20 Correct 174 ms 329144 KB Output is correct
21 Correct 157 ms 329004 KB Output is correct
22 Correct 147 ms 329004 KB Output is correct
23 Correct 146 ms 329072 KB Output is correct
24 Correct 151 ms 329056 KB Output is correct
25 Correct 154 ms 329000 KB Output is correct
26 Correct 149 ms 328976 KB Output is correct
27 Correct 153 ms 328996 KB Output is correct
28 Correct 163 ms 329008 KB Output is correct
29 Correct 156 ms 329036 KB Output is correct
30 Correct 169 ms 328968 KB Output is correct
31 Execution timed out 2094 ms 329136 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 329036 KB Output is correct
2 Correct 144 ms 329064 KB Output is correct
3 Correct 160 ms 329060 KB Output is correct
4 Correct 151 ms 329196 KB Output is correct
5 Correct 151 ms 329072 KB Output is correct
6 Correct 163 ms 329000 KB Output is correct
7 Correct 149 ms 329016 KB Output is correct
8 Correct 162 ms 329248 KB Output is correct
9 Correct 151 ms 329044 KB Output is correct
10 Correct 153 ms 329092 KB Output is correct
11 Correct 164 ms 329092 KB Output is correct
12 Correct 149 ms 328980 KB Output is correct
13 Correct 148 ms 329004 KB Output is correct
14 Correct 157 ms 329096 KB Output is correct
15 Correct 149 ms 329200 KB Output is correct
16 Correct 150 ms 329156 KB Output is correct
17 Execution timed out 2078 ms 328968 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 329036 KB Output is correct
2 Correct 144 ms 329064 KB Output is correct
3 Correct 160 ms 329060 KB Output is correct
4 Correct 151 ms 329196 KB Output is correct
5 Correct 151 ms 329072 KB Output is correct
6 Correct 163 ms 329000 KB Output is correct
7 Correct 149 ms 329016 KB Output is correct
8 Correct 162 ms 329248 KB Output is correct
9 Correct 151 ms 329044 KB Output is correct
10 Correct 153 ms 329092 KB Output is correct
11 Correct 164 ms 329092 KB Output is correct
12 Correct 149 ms 328980 KB Output is correct
13 Correct 148 ms 329004 KB Output is correct
14 Correct 157 ms 329096 KB Output is correct
15 Correct 149 ms 329200 KB Output is correct
16 Correct 150 ms 329156 KB Output is correct
17 Execution timed out 2078 ms 328968 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 329036 KB Output is correct
2 Correct 144 ms 329064 KB Output is correct
3 Correct 160 ms 329060 KB Output is correct
4 Correct 151 ms 329196 KB Output is correct
5 Correct 151 ms 329072 KB Output is correct
6 Correct 163 ms 329000 KB Output is correct
7 Correct 149 ms 329016 KB Output is correct
8 Correct 162 ms 329248 KB Output is correct
9 Correct 151 ms 329044 KB Output is correct
10 Correct 153 ms 329092 KB Output is correct
11 Correct 164 ms 329092 KB Output is correct
12 Correct 149 ms 328980 KB Output is correct
13 Correct 148 ms 329004 KB Output is correct
14 Correct 157 ms 329096 KB Output is correct
15 Correct 149 ms 329200 KB Output is correct
16 Correct 150 ms 329156 KB Output is correct
17 Execution timed out 2078 ms 328968 KB Time limit exceeded
18 Halted 0 ms 0 KB -