Submission #385483

# Submission time Handle Problem Language Result Execution time Memory
385483 2021-04-04T13:23:00 Z ogibogi2004 Robots (APIO13_robots) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("fma,avx,avx2")
#define ends dfdsfdsf
const int INF=1e8;
pair<pair<int,int>,int> nxt[512][512][4];
vector<pair<pair<int,int>,int> >g[512][512][4];
vector<pair<int,int> >g1[512][512];
char table[512][512];
int r,n,m;
vector<pair<pair<int,int>,int> >ends;
pair<pair<int,int>,int> actual_nxt[512][512][4];
bool not_valid(pair<int,int> p)
{
	int x=p.first,y=p.second;
	if(x<1||y<1||x>n||y>m)return 1;
	return table[x][y]=='x';
}
int dp[10][10][512][512];
pair<int,int> where[10];
int main()
{
	cin>>r>>m>>n;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			cin>>table[i][j];
			if(isdigit(table[i][j]))
			{
				where[table[i][j]-'0']={i,j};
			}
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(table[i][j]=='x')continue;
			if(table[i][j]=='A')
			{
				nxt[i][j][0]={{i,j-1},3};
				nxt[i][j][1]={{i-1,j},0};
				nxt[i][j][2]={{i,j+1},1};
				nxt[i][j][3]={{i+1,j},2};
			}
			else if(table[i][j]=='C')
			{
				nxt[i][j][0]={{i,j+1},1};
				nxt[i][j][1]={{i+1,j},2};
				nxt[i][j][2]={{i,j-1},3};
				nxt[i][j][3]={{i-1,j},0};
			}
			else
			{
				nxt[i][j][0]={{i-1,j},0};
				nxt[i][j][1]={{i,j+1},1};
				nxt[i][j][2]={{i+1,j},2};
				nxt[i][j][3]={{i,j-1},3};
			}
			for(int l=0;l<4;++l)
			{
				if(not_valid(nxt[i][j][l].first))
				{
					ends.push_back({{i,j},l});
				}
				g[nxt[i][j][l].first.first][nxt[i][j][l].first.second][nxt[i][j][l].second].push_back({{i,j},l});
			}
		}
	}
	queue<pair<pair<int,int>,int> >q;
	for(auto xd:ends)
	{
		q.push(xd);
		actual_nxt[xd.first.first][xd.first.second][xd.second]=xd;
	}
	while(!q.empty())
	{
		auto u=q.front();
		q.pop();
		for(auto xd:g[u.first.first][u.first.second][u.second])
		{
			actual_nxt[xd.first.first][xd.first.second][xd.second]=actual_nxt[u.first.first][u.first.second][u.second];
			q.push(xd);
		}
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			for(int l=0;l<4;++l)
			{
				int x,y,z;
				x=actual_nxt[i][j][l].first.first;
				y=actual_nxt[i][j][l].first.second;
				z=actual_nxt[i][j][l].second;
				if(x==i&&y==j&&z==l)continue;
				g1[i][j].push_back({x,y});
			}
		}
	}
	for(int r1=1;r1<=r;++r1)
	{
		for(int r2=1;r2<=r;++r2)
		{
			for(int i1=1;i1<=n;++i1)
			{
				for(int i2=1;i2<=m;++i2)
				{
					dp[r1][r2][i1][i2]=INF;
				}
			}
		}
	}
	queue<pair<int,int> >q;
	for(int i=1;i<=r;++i)
	{
		int x,y;
		x=where[i].first;
		y=where[i].second;
		q.push({x,y});
		dp[i][i][x][y]=0;
		while(!q.empty())
		{
			tie(x,y)=q.front();
			q.pop();
			for(auto xd:g1[x][y])
			{
				if(dp[i][i][xd.first][xd.second]>dp[i][i][x][y]+1)
				{
					dp[i][i][xd.first][xd.second]=dp[i][i][x][y]+1;
					q.push(xd);
				}
			}
		}
	}
	priority_queue<pair<int,pair<int,int> > >pq;
	for(int len=2;len<=r;++len)
	{
		for(int r1=1;r1+len-1<=r;++r1)
		{
			int r2=r1+len-1;
			for(int mid=r1;mid<r2;++mid)
			{
				for(int i=1;i<=n;++i)
				{
					for(int j=1;j<=m;++j)
					{
						dp[r1][r2][i][j]=min(dp[r1][r2][i][j],dp[r1][mid][i][j]+dp[mid+1][r2][i][j]);
					}
				}
			}
			for(int i=1;i<=n;++i)
			{
				for(int j=1;j<=m;++j)
				{
					pq.push({-dp[r1][r2][i][j],{i,j}});
				}
			}
			while(!pq.empty())
			{
				int x,y;
				int t;
				t=pq.top().first;
				tie(x,y)=pq.top().second;
				pq.pop();
				if(t!=-dp[r1][r2][x][y])continue;
				for(auto xd:g1[x][y])
				{
					if(dp[r1][r2][x][y]+1<dp[r1][r2][xd.first][xd.second])
					{
						dp[r1][r2][xd.first][xd.second]=dp[r1][r2][x][y]+1;
						pq.push({-dp[r1][r2][xd.first][xd.second],{xd}});
					}
				}
			}
		}
	}
	/*for(int i1=1;i1<=r;i1++)
	{
		for(int i2=i1;i2<=r;i2++)
		{
			cout<<i1<<"-"<<i2<<endl;
			for(int i=1;i<=n;i++)
			{
				for(int j=1;j<=m;j++)
				{
					if(dp[i1][i2][i][j]<INF)cout<<dp[i1][i2][i][j];
					else cout<<"x";
				}
				cout<<endl;
			}
		}
	}*/
	int ans=INF;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			ans=min(ans,dp[1][r][i][j]);
		}
	}
	if(ans==INF)cout<<"-1\n";
	else cout<<ans<<endl;
return 0;
}

Compilation message

robots.cpp: In function 'int main()':
robots.cpp:116:23: error: conflicting declaration 'std::queue<std::pair<int, int> > q'
  116 |  queue<pair<int,int> >q;
      |                       ^
robots.cpp:72:33: note: previous declaration as 'std::queue<std::pair<std::pair<int, int>, int> > q'
   72 |  queue<pair<pair<int,int>,int> >q;
      |                                 ^
robots.cpp:122:15: error: no matching function for call to 'std::queue<std::pair<std::pair<int, int>, int> >::push(<brace-enclosed initializer list>)'
  122 |   q.push({x,y});
      |               ^
In file included from /usr/include/c++/9/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from robots.cpp:1:
/usr/include/c++/9/bits/stl_queue.h:259:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<std::pair<int, int>, int>; _Sequence = std::deque<std::pair<std::pair<int, int>, int>, std::allocator<std::pair<std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<std::pair<int, int>, int>]'
  259 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_queue.h:259:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<std::pair<int, int>, int>&'}
  259 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_queue.h:264:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<std::pair<int, int>, int>; _Sequence = std::deque<std::pair<std::pair<int, int>, int>, std::allocator<std::pair<std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<std::pair<int, int>, int>]'
  264 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_queue.h:264:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<std::pair<int, int>, int> >::value_type&&' {aka 'std::pair<std::pair<int, int>, int>&&'}
  264 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
robots.cpp:126:21: error: no match for 'operator=' (operand types are 'std::tuple<int&, int&>' and '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'})
  126 |    tie(x,y)=q.front();
      |                     ^
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from robots.cpp:1:
/usr/include/c++/9/tuple:1205:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(typename std::conditional<__assignable<const _T1&, const _T2&>(), const std::tuple<_T1, _T2>&, const std::__nonesuch_no_braces&>::type) [with _T1 = int&; _T2 = int&; typename std::conditional<__assignable<const _T1&, const _T2&>(), const std::tuple<_T1, _T2>&, const std::__nonesuch_no_braces&>::type = const std::tuple<int&, int&>&]'
 1205 |       operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
      |       ^~~~~~~~
/usr/include/c++/9/tuple:1207:45: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} to 'std::conditional<true, const std::tuple<int&, int&>&, const std::__nonesuch_no_braces&>::type' {aka 'const std::tuple<int&, int&>&'}
 1205 |       operator=(typename conditional<__assignable<const _T1&, const _T2&>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1206 |          const tuple&,
      |          ~~~~~~~~~~~~~                       
 1207 |          const __nonesuch_no_braces&>::type __in)
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/9/tuple:1215:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(typename std::conditional<__assignable<_T1, _T2>(), std::tuple<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type) [with _T1 = int&; _T2 = int&; typename std::conditional<__assignable<_T1, _T2>(), std::tuple<_T1, _T2>&&, std::__nonesuch_no_braces&&>::type = std::tuple<int&, int&>&&]'
 1215 |       operator=(typename conditional<__assignable<_T1, _T2>(),
      |       ^~~~~~~~
/usr/include/c++/9/tuple:1217:40: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} to 'std::conditional<true, std::tuple<int&, int&>&&, std::__nonesuch_no_braces&&>::type' {aka 'std::tuple<int&, int&>&&'}
 1215 |       operator=(typename conditional<__assignable<_T1, _T2>(),
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1216 |          tuple&&,
      |          ~~~~~~~~                       
 1217 |          __nonesuch_no_braces&&>::type __in)
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
/usr/include/c++/9/tuple:1226:2: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1226 |  operator=(const tuple<_U1, _U2>& __in)
      |  ^~~~~~~~
/usr/include/c++/9/tuple:1226:2: note:   template argument deduction/substitution failed:
robots.cpp:126:21: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} is not derived from 'const std::tuple<_T1, _T2>'
  126 |    tie(x,y)=q.front();
      |                     ^
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from robots.cpp:1:
/usr/include/c++/9/tuple:1235:2: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1235 |  operator=(tuple<_U1, _U2>&& __in)
      |  ^~~~~~~~
/usr/include/c++/9/tuple:1235:2: note:   template argument deduction/substitution failed:
robots.cpp:126:21: note:   '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<int, int>, int> >, std::pair<std::pair<int, int>, int> >::value_type' {aka 'std::pair<std::pair<int, int>, int>'} is not derived from 'std::tuple<_T1, _T2>'
  126 |    tie(x,y)=q.front();
      |                     ^
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from robots.cpp:1:
/usr/include/c++/9/tuple:1244:2: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1244 |  operator=(const pair<_U1, _U2>& __in)
      |  ^~~~~~~~
/usr/include/c++/9/tuple:1244:2: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/move.h:55,
                 from /usr/include/c++/9/bits/nested_exception.h:40,
                 from /usr/include/c++/9/exception:144,
                 from /usr/include/c++/9/ios:39,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from robots.cpp:1:
/usr/include/c++/9/type_traits: In substitution of 'template<bool _Cond, class _Tp> using __enable_if_t = typename std::enable_if::type [with bool _Cond = std::tuple<int&, int&>::__assignable<const std::pair<int, int>&, const int&>(); _Tp = std::tuple<int&, int&>&]':
/usr/include/c++/9/tuple:1244:2:   required by substitution of 'template<class _U1, class _U2> std::__enable_if_t<__assignable<const _U1&, const _U2&>(), std::tuple<int&, int&>&> std::tuple<int&, int&>::operator=<_U1, _U2>(const std::pair<_T1, _T2>&) [with _U1 = std::pair<int, int>; _U2 = int]'
robots.cpp:126:21:   required from here
/usr/include/c++/9/type_traits:2405:11: error: no type named 'type' in 'struct std::enable_if<false, std::tuple<int&, int&>&>'
 2405 |     using __enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~~~
In file included from /usr/include/c++/9/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:71,
                 from robots.cpp:1:
/usr/include/c++/9/tuple:1254:2: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<__assignable<_U1, _U2>(), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int&; _T2 = int&]'
 1254 |  operator=(pair<_U1, _U2>&& __in)
      |  ^~~~~~~~
/usr/include/c++/9/tuple:1254:2: note:   template argument deduction/substitution failed:
robots.cpp:133:15: error: no matching function for call to 'std::queue<std::pair<std::pair<int, int>, int> >::push(std::pair<int, int>&)'
  133 |      q.push(xd);
      |               ^
In file included from /usr/include/c++/9/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:86,
                 from robots.cpp:1:
/usr/include/c++/9/bits/stl_queue.h:259:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<std::pair<int, int>, int>; _Sequence = std::deque<std::pair<std::pair<int, int>, int>, std::allocator<std::pair<std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<std::pair<int, int>, int>]'
  259 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_queue.h:259:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const value_type&' {aka 'const std::pair<std::pair<int, int>, int>&'}
  259 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_queue.h:264:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(std::queue<_Tp, _Sequence>::value_type&&) [with _Tp = std::pair<std::pair<int, int>, int>; _Sequence = std::deque<std::pair<std::pair<int, int>, int>, std::allocator<std::pair<std::pair<int, int>, int> > >; std::queue<_Tp, _Sequence>::value_type = std::pair<std::pair<int, int>, int>]'
  264 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/9/bits/stl_queue.h:264:25: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::queue<std::pair<std::pair<int, int>, int> >::value_type&&' {aka 'std::pair<std::pair<int, int>, int>&&'}
  264 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~