Submission #709350

# Submission time Handle Problem Language Result Execution time Memory
709350 2023-03-13T12:59:28 Z Antekb Golf (JOI17_golf) C++17
30 / 100
563 ms 91752 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){
	cerr<<h;
	if(sizeof...(t))cerr<<", ";
	debug(t...);
}
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
const int N=2005, INF=1e9+5;
int d[N][N], czy[N][N][4];
vector<pii> edg={{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int main(){
	map<int, int> Mx, My;
	int xp, yp, xk, yk;
	cin>>xp>>yp>>xk>>yk;
	Mx[xp]=1;
	My[yp]=1;
	Mx[xk]=1;
	My[yk]=1;
	int n;
	cin>>n;
	vector<pair<pii, pii> > rec(n);
	for(int i=0; i<n; i++){
		cin>>rec[i].st.st>>rec[i].st.nd>>rec[i].nd.st>>rec[i].nd.nd;
		Mx[rec[i].st.st]=1;
		Mx[rec[i].st.nd]=1;
		My[rec[i].nd.st]=1;
		My[rec[i].nd.nd]=1;
	}
	int wskx=0;
	for(auto &i:Mx){
		i.nd=wskx++;
	}
	xp=Mx[xp];
	xk=Mx[xk];
	for(int i=0; i<n; i++){
		rec[i].st.st=Mx[rec[i].st.st];
		rec[i].st.nd=Mx[rec[i].st.nd];
	}
	int wsky=0;
	for(auto &i:My){
		i.nd=wsky++;
	}
	yp=My[yp];
	yk=My[yk];
	for(int i=0; i<n; i++){
		rec[i].nd.st=My[rec[i].nd.st];
		rec[i].nd.nd=My[rec[i].nd.nd];
	}
	for(int i=0; i<wskx; i++){
		for(int j=0; j<wsky; j++){
			for(int k=0; k<4; k++){
				d[i][j]=1e9;
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int j=rec[i].st.st+1; j<=rec[i].st.nd-1; j++){	
			czy[j][rec[i].nd.st][1]=1;
			czy[j][rec[i].nd.nd][3]=1;
		}
		for(int k=rec[i].nd.st+1; k<=rec[i].nd.nd-1; k++){
			czy[rec[i].st.st][k][0]=1;
			czy[rec[i].st.nd][k][2]=1;
		}
	}
	//deb(xp, yp);
	//deb(xk, yk);
	//deb(rec[0].st.st, rec[0].st.nd, rec[0].nd.st, rec[0].nd.nd);
	vector<pair<int, int> > V;
	d[xp][yp]=0;
	V.eb(xp, yp);
	//deb(wskx, wsky);
	for(int i=0; i<V.size(); i++){
		int x=V[i].st, y=V[i].nd;
		//deb(x, y, d[x][y]);
		int dist=d[x][y];
		for(int xx=x+1; xx<wskx; xx++){
			if(d[xx][y]<=dist || czy[xx-1][y][0])break;
			//deb(xx, y);
			if(d[xx][y]>dist+1)d[xx][y]=dist+1, V.eb(xx, y);
		}
		for(int xx=x-1; xx>=0; xx--){
			if(d[xx][y]<=dist || czy[xx+1][y][2])break;
			if(d[xx][y]>dist+1)d[xx][y]=dist+1, V.eb(xx, y);
		}
		
		for(int yy=y+1; yy<wsky; yy++){
			if(d[x][yy]<=dist || czy[x][yy-1][1])break;
			if(d[x][yy]>dist+1)d[x][yy]=dist+1, V.eb(x, yy);
		}
		for(int yy=y-1; yy>=0; yy--){
			if(d[x][yy]<=dist || czy[x][yy+1][3])break;
			if(d[x][yy]>dist+1)d[x][yy]=dist+1, V.eb(x, yy);
		}
	}
	cout<<d[xk][yk];
}

Compilation message

golf.cpp: In function 'int main()':
golf.cpp:88:16: 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<V.size(); i++){
      |               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 19 ms 22336 KB Output is correct
6 Correct 15 ms 21600 KB Output is correct
7 Correct 22 ms 20824 KB Output is correct
8 Correct 18 ms 21984 KB Output is correct
9 Correct 19 ms 20428 KB Output is correct
10 Correct 24 ms 22288 KB Output is correct
11 Correct 20 ms 25032 KB Output is correct
12 Correct 15 ms 21872 KB Output is correct
13 Correct 16 ms 21960 KB Output is correct
14 Correct 18 ms 24012 KB Output is correct
15 Correct 8 ms 8880 KB Output is correct
16 Correct 33 ms 27736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 19 ms 22336 KB Output is correct
6 Correct 15 ms 21600 KB Output is correct
7 Correct 22 ms 20824 KB Output is correct
8 Correct 18 ms 21984 KB Output is correct
9 Correct 19 ms 20428 KB Output is correct
10 Correct 24 ms 22288 KB Output is correct
11 Correct 20 ms 25032 KB Output is correct
12 Correct 15 ms 21872 KB Output is correct
13 Correct 16 ms 21960 KB Output is correct
14 Correct 18 ms 24012 KB Output is correct
15 Correct 8 ms 8880 KB Output is correct
16 Correct 33 ms 27736 KB Output is correct
17 Correct 86 ms 87692 KB Output is correct
18 Correct 107 ms 90308 KB Output is correct
19 Correct 82 ms 85032 KB Output is correct
20 Correct 79 ms 91752 KB Output is correct
21 Correct 85 ms 88120 KB Output is correct
22 Correct 84 ms 89308 KB Output is correct
23 Correct 81 ms 87876 KB Output is correct
24 Correct 72 ms 84744 KB Output is correct
25 Correct 75 ms 86296 KB Output is correct
26 Correct 79 ms 86184 KB Output is correct
27 Correct 12 ms 11020 KB Output is correct
28 Correct 42 ms 30988 KB Output is correct
29 Correct 38 ms 31592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 19 ms 22336 KB Output is correct
6 Correct 15 ms 21600 KB Output is correct
7 Correct 22 ms 20824 KB Output is correct
8 Correct 18 ms 21984 KB Output is correct
9 Correct 19 ms 20428 KB Output is correct
10 Correct 24 ms 22288 KB Output is correct
11 Correct 20 ms 25032 KB Output is correct
12 Correct 15 ms 21872 KB Output is correct
13 Correct 16 ms 21960 KB Output is correct
14 Correct 18 ms 24012 KB Output is correct
15 Correct 8 ms 8880 KB Output is correct
16 Correct 33 ms 27736 KB Output is correct
17 Correct 86 ms 87692 KB Output is correct
18 Correct 107 ms 90308 KB Output is correct
19 Correct 82 ms 85032 KB Output is correct
20 Correct 79 ms 91752 KB Output is correct
21 Correct 85 ms 88120 KB Output is correct
22 Correct 84 ms 89308 KB Output is correct
23 Correct 81 ms 87876 KB Output is correct
24 Correct 72 ms 84744 KB Output is correct
25 Correct 75 ms 86296 KB Output is correct
26 Correct 79 ms 86184 KB Output is correct
27 Correct 12 ms 11020 KB Output is correct
28 Correct 42 ms 30988 KB Output is correct
29 Correct 38 ms 31592 KB Output is correct
30 Runtime error 563 ms 76472 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -