답안 #895064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895064 2023-12-29T11:29:11 Z Muhammad_Aneeq 분수 공원 (IOI21_parks) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
#include <map>
#include <queue>
using namespace std;
map<pair<int,int>,int>d,vis;
vector<pair<int,int>>z;
queue<pair<int,int>>Q;
int x1=0,y11=0;
void check(int x,int y)
{
	if (d.find({x,y})!=d.end()&&!vis[{x,y}])
	{
		Q.push({x,y});
		vis[{x,y}]=1;
		z.push_back({d[{x1,y11}],d[{x,y}]});
	}
}
void bfs(int x,int y)
{
	Q.push({x,y});
	vis[{x,y}]=1;
	while (Q.size())
	{
		x,y;
		tie(x,y)=Q.front();
		x1=x,y11=y;
		Q.pop();
		check(x,y-2);
		check(x,y+2);
		check(x-2,y);
		check(x+2,y);
	}
}
int construct_roads(vector<int> x, vector<int> y)
{
	int n=x.size();
	for (int i=0;i<n;i++)
		d[{x[i],y[i]}]=i;
	int reqx=1e9+10,reqy=1e9+10;
	for (int i=0;i<n;i++)
	{
		if (x[i]<reqx)
		{
			reqx=x[i];
			reqy=y[i];
		}
		else if (x[i]==reqx&&reqy<y[i])
			reqy=y[i];
	}
	bfs(reqx,reqy);
	for (int i=0;i<n;i++)
	{
		if (!vis[{x[i],y[i]}])
			return 0;
	}
	vis={};
	vector<int>u,v,a,b;
	cout<<endl;
	for (auto i:z)
	{
		u.push_back(i.first);
		v.push_back(i.second);
		pair<int,int>r,q;
		r.first=x[i.first],r.second=y[i.first];
		q.first=x[i.second],q.second=y[i.second];
		if (r.first-q.first==0)
		{
			a.push_back(r.first-1);
			b.push_back((r.second+q.second)/2);
			if (vis[{a.back(),b.back()}])
			{
				a.pop_back();
				a.push_back(r.first+1);
				if (vis[{a.back(),b.back()}])
					return 0;
				vis[{a.back(),b.back()}]=1;
			}
			else
				vis[{a.back(),b.back()}]=1;
		}
		else
		{
			a.push_back((r.first+q.first)/2);
			b.push_back(r.second-1);
			if (vis[{a.back(),b.back()}])
			{
				b.pop_back();
				b.push_back(r.second+1);
				if (vis[{a.back(),b.back()}])
					return 0;
				vis[{a.back(),b.back()}]=1;
			}
			else
				vis[{a.back(),b.back()}]=1;
		}
	}
	build(u,v,a,b);
	return 1;
}

Compilation message

parks.cpp: In function 'void bfs(int, int)':
parks.cpp:24:3: warning: left operand of comma operator has no effect [-Wunused-value]
   24 |   x,y;
      |   ^
parks.cpp:24:6: warning: right operand of comma operator has no effect [-Wunused-value]
   24 |   x,y;
      |      ^
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:58:2: error: 'cout' was not declared in this scope
   58 |  cout<<endl;
      |  ^~~~
parks.cpp:4:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    3 | #include <queue>
  +++ |+#include <iostream>
    4 | using namespace std;
parks.cpp:58:8: error: 'endl' was not declared in this scope
   58 |  cout<<endl;
      |        ^~~~
parks.cpp:4:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
    3 | #include <queue>
  +++ |+#include <ostream>
    4 | using namespace std;
parks.cpp:97:2: error: 'build' was not declared in this scope
   97 |  build(u,v,a,b);
      |  ^~~~~