Submission #826815

# Submission time Handle Problem Language Result Execution time Memory
826815 2023-08-16T04:55:55 Z 반딧불(#10373) Golf (JOI17_golf) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct Rect{
	int xl, yl, xr, yr;
	Rect(){}
	Rect(int xl, int yl, int xr, int yr): xl(xl), yl(yl), xr(xr), yr(yr){}
};

int x1, y1, x2, y2;
int n;
Rect rects[100002];

void renumber();
void solve();

int main(){
	scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &n);
	for(int i=1; i<=n; i++){
		scanf("%d %d %d %d", &rects[i].xl, &rects[i].xr, &rects[i].yl, &rects[i].yr);
	}

	renumber();
	solve();
}

int H, W;

void renumber(){
	vector<int> vx, vy;
	vx.push_back(x1), vx.push_back(x2), vy.push_back(y1), vy.push_back(y2);
	for(int i=1; i<=n; i++){
		vx.push_back(rects[i].xl), vx.push_back(rects[i].xr);
		vy.push_back(rects[i].yl), vy.push_back(rects[i].yr);
	}
	sort(vx.begin(), vx.end());
	vx.erase(unique(vx.begin(), vx.end()), vx.end());
	sort(vy.begin(), vy.end());
	vy.erase(unique(vy.begin(), vy.end()), vy.end());
	H = (int)vx.size();
	W = (int)vy.size();
	x1 = lower_bound(vx.begin(), vx.end(), x1) - vx.begin() + 1;
	x2 = lower_bound(vx.begin(), vx.end(), x2) - vx.begin() + 1;
	y1 = lower_bound(vy.begin(), vy.end(), y1) - vy.begin() + 1;
	y2 = lower_bound(vy.begin(), vy.end(), y2) - vy.begin() + 1;
	for(int i=1; i<=n; i++){
		rects[i].xl = lower_bound(vx.begin(), vx.end(), rects[i].xl) - vx.begin() + 1;
		rects[i].xr = lower_bound(vx.begin(), vx.end(), rects[i].xr) - vx.begin() + 1;
		rects[i].yl = lower_bound(vy.begin(), vy.end(), rects[i].yl) - vy.begin() + 1;
		rects[i].yr = lower_bound(vy.begin(), vy.end(), rects[i].yr) - vy.begin() + 1;
	}
}

struct dat{
	int x, y, dir, dist;
	dat(){}
	dat(int x, int y, int dir, int dist): x(x), y(y), dir(dir), dist(dist){}
};

const int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0};
deque<dat> dq;
bool visited[2102][2102][4];
int dist[2102][2102][4];
bool passable[2102][2102][4];

void solve(){
	for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) for(int d=0; d<4; d++) passable[i][j][d] = 1;
	for(int i=1; i<=n; i++){
		int xl = rects[i].xl, xr = rects[i].xr, yl = rects[i].yl, yr = rects[i].yr;
		for(int x=xl+1; x<xr; x++) for(int y=yl; y<yr; y++) passable[x][y][0] = false;
		for(int x=xl; x<xr; x++) for(int y=yl+1; y<yr; y++) passable[x][y][1] = false;
		for(int x=xl+1; x<xr; x++) for(int y=yl+1; y<=yr; y++) passable[x][y][2] = false;
		for(int x=xl+1; x<=xr; x++) for(int y=yl+1; y<yr; y++) passable[x][y][3] = false;
	}

	for(int i=0; i<4; i++) dq.push_back(dat(x1, y1, i, 1));
	while(!dq.empty()){
		dat tmp = dq.front(); dq.pop_front();
		if(visited[tmp.x][tmp.y][tmp.dir]) continue;
		visited[tmp.x][tmp.y][tmp.dir] = 1;
		dist[tmp.x][tmp.y][tmp.dir] = tmp.dist;
		//printf("%d %d %d: %d\n", tmp.x, tmp.y, tmp.dir, tmp.dist);
		if(tmp.x == x2 && tmp.y == y2){
			printf("%d", tmp.dist);
			exit(0);
		}
		for(int d=0; d<4; d++){
			int tx = tmp.x + xx[d], ty = tmp.y + yy[d];
			if(tx<1 || tx>H || ty<1 || ty>W || !passable[tx][ty][d]) continue;
			if(d == tmp.dir) dq.push_front(dat(tx, ty, d, tmp.dist));
			else dq.push_back(dat(tx, ty, d, tmp.dist+1));
		}
	}
	printf("-1");
}

Compilation message

golf.cpp:13:9: error: 'int y1' redeclared as different kind of entity
   13 | int x1, y1, x2, y2;
      |         ^~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from golf.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:221:1: note: previous declaration 'double y1(double)'
  221 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
golf.cpp: In function 'int main()':
golf.cpp:21:13: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'double (*)(double) noexcept' [-Wformat=]
   21 |  scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &n);
      |            ~^                 ~~~
      |             |                 |
      |             int*              double (*)(double) noexcept
golf.cpp: In function 'void renumber()':
golf.cpp:34:53: error: no matching function for call to 'push_back(double (&)(double) noexcept)'
   34 |  vx.push_back(x1), vx.push_back(x2), vy.push_back(y1), vy.push_back(y2);
      |                                                     ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from golf.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]' (near match)
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:7: note:   conversion of argument 1 would be ill-formed:
golf.cpp:34:51: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<int>::value_type' {aka 'int'} [-fpermissive]
   34 |  vx.push_back(x1), vx.push_back(x2), vy.push_back(y1), vy.push_back(y2);
      |                                                   ^~
      |                                                   |
      |                                                   double (*)(double) noexcept
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from golf.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]' (near match)
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note:   conversion of argument 1 would be ill-formed:
golf.cpp:34:51: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<int>::value_type' {aka 'int'} [-fpermissive]
   34 |  vx.push_back(x1), vx.push_back(x2), vy.push_back(y1), vy.push_back(y2);
      |                                                   ^~
      |                                                   |
      |                                                   double (*)(double) noexcept
golf.cpp:47:5: error: assignment of function 'double y1(double)'
   47 |  y1 = lower_bound(vy.begin(), vy.end(), y1) - vy.begin() + 1;
      |  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp: In function 'void solve()':
golf.cpp:79:46: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   79 |  for(int i=0; i<4; i++) dq.push_back(dat(x1, y1, i, 1));
      |                                              ^~
      |                                              |
      |                                              double (*)(double) noexcept
golf.cpp:60:17: note:   initializing argument 2 of 'dat::dat(int, int, int, int)'
   60 |  dat(int x, int y, int dir, int dist): x(x), y(y), dir(dir), dist(dist){}
      |             ~~~~^
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from golf.cpp:1:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Value = double(double) noexcept]':
/usr/include/c++/10/bits/stl_algobase.h:1324:14:   required from '_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Tp = double(double) noexcept; _Compare = __gnu_cxx::__ops::_Iter_less_val]'
/usr/include/c++/10/bits/stl_algobase.h:1359:32:   required from '_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; _Tp = double(double) noexcept]'
golf.cpp:47:43:   required from here
/usr/include/c++/10/bits/predefined_ops.h:67:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   67 |       { return *__it < __val; }
      |                ~~~~~~^~~~~~~
golf.cpp: In function 'int main()':
golf.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
golf.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   scanf("%d %d %d %d", &rects[i].xl, &rects[i].xr, &rects[i].yl, &rects[i].yr);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~