fork download
  1. #include<iostream>
  2. #include<queue>
  3. #include<algorithm>
  4. using namespace std;
  5. struct pqitem{
  6. int v,x,y;
  7. bool operator<(pqitem b)const
  8. {return v>b.v;}
  9. };
  10. int n;
  11. int w1,h1,x1,y1;
  12. int w2,h2,x2,y2;
  13. int g[2][500][500];
  14. int c[2][250000];
  15. vector<pqitem> fourway(int x,int y,int w,int h)
  16. {
  17. vector<pqitem> ans;
  18. if(x>0)ans.push_back({0,x-1,y});
  19. if(y>0)ans.push_back({0,x,y-1});
  20. if(x<h-1)ans.push_back({0,x+1,y});
  21. if(y<w-1)ans.push_back({0,x,y+1});
  22. return ans;
  23. }
  24. void bfs(int i,int x,int y,int w,int h)
  25. {
  26. bool u[500][500]={};
  27. priority_queue<pqitem> q;
  28. q.push({1,x,y});
  29. u[x][y]=1;
  30. int j=1;
  31. c[i][0]=0;
  32. while(!q.empty())
  33. {
  34. pqitem now=q.top();
  35. q.pop();
  36. c[i][j++]=now.v;
  37. vector<pqitem> fw=fourway(now.x,now.y,w,h);
  38. for(pqitem &t:fw)
  39. if(!u[t.x][t.y])
  40. {
  41. t.v=g[i][t.x][t.y];
  42. q.push(t);
  43. u[t.x][t.y]=1;
  44. }
  45. }
  46. for(int k=1;k<j;k++)
  47. c[i][k]=max(c[i][k],c[i][k-1]);
  48. for(int k=j;k<=n;k++)
  49. c[i][k]=1e9;
  50. }
  51. int main()
  52. {
  53. ios::sync_with_stdio(0);
  54. cin>>n;
  55. cin>>w1>>h1>>x1>>y1;
  56. for(int i=0;i<h1;i++)
  57. for(int j=0;j<w1;j++)
  58. cin>>g[0][i][j];
  59. cin>>w2>>h2>>x2>>y2;
  60. for(int i=0;i<h2;i++)
  61. for(int j=0;j<w2;j++)
  62. cin>>g[1][i][j];
  63. x1--; y1--; x2--; y2--;
  64. swap(x1,y1); swap(x2,y2);
  65. bfs(0,x1,y1,w1,h1);
  66. bfs(1,x2,y2,w2,h2);
  67. int ans=1e9;
  68. for(int i=0;i<=n;i++)
  69. {
  70. ans=min(ans,c[0][i]+c[1][n-i]);
  71. }
  72. cout<<ans<<endl;
  73. }
  74.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:11:14: error: ‘int y1’ redeclared as different kind of symbol
 int w1,h1,x1,y1;
              ^
In file included from /usr/include/features.h:371:0,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/os_defines.h:39,
                 from /usr/include/i386-linux-gnu/c++/4.8/bits/c++config.h:426,
                 from /usr/include/c++/4.8/iostream:38,
                 from prog.cpp:1:
/usr/include/i386-linux-gnu/bits/mathcalls.h:242:1: error: previous declaration of ‘double y1(double)’
 __MATHCALL (y1,, (_Mdouble_));
 ^
prog.cpp: In function ‘int main()’:
prog.cpp:55:13: error: cannot bind ‘std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}’ lvalue to ‘std::basic_istream<char>&&’
  cin>>w1>>h1>>x1>>y1;
             ^
In file included from /usr/include/c++/4.8/iostream:40:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/istream:872:5: error:   initializing argument 1 of ‘std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = double(double)throw ()]’
     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
     ^
prog.cpp:63:10: error: ISO C++ forbids decrementing a pointer of type ‘double (*)(double)throw ()’ [-fpermissive]
  x1--; y1--; x2--; y2--;
          ^
prog.cpp:63:10: error: lvalue required as decrement operand
prog.cpp:64:12: error: no matching function for call to ‘swap(int&, double (&)(double)throw ())’
  swap(x1,y1); swap(x2,y2);
            ^
prog.cpp:64:12: note: candidates are:
In file included from /usr/include/c++/4.8/bits/stl_pair.h:59:0,
                 from /usr/include/c++/4.8/bits/stl_algobase.h:64,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/move.h:166:5: note: template<class _Tp> void std::swap(_Tp&, _Tp&)
     swap(_Tp& __a, _Tp& __b)
     ^
/usr/include/c++/4.8/bits/move.h:166:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   deduced conflicting types for parameter ‘_Tp’ (‘int’ and ‘double(double)throw ()’)
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/bits/stl_pair.h:59:0,
                 from /usr/include/c++/4.8/bits/stl_algobase.h:64,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/move.h:185:5: note: template<class _Tp, unsigned int _Nm> void std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
     ^
/usr/include/c++/4.8/bits/move.h:185:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘_Tp [_Nm]’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_pair.h:254:5: note: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
     ^
/usr/include/c++/4.8/bits/stl_pair.h:254:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::pair<_T1, _T2>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2717:5: note: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::basic_string<_CharT, _Traits, _Alloc>&, std::basic_string<_CharT, _Traits, _Alloc>&)
     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^
/usr/include/c++/4.8/bits/basic_string.h:2717:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::basic_string<_CharT, _Traits, _Alloc>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/deque:64:0,
                 from /usr/include/c++/4.8/queue:60,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_deque.h:2011:5: note: template<class _Tp, class _Alloc> void std::swap(std::deque<_Tp, _Alloc>&, std::deque<_Tp, _Alloc>&)
     swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
     ^
/usr/include/c++/4.8/bits/stl_deque.h:2011:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::deque<_Tp, _Alloc>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/vector:64:0,
                 from /usr/include/c++/4.8/queue:61,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_vector.h:1451:5: note: template<class _Tp, class _Alloc> void std::swap(std::vector<_Tp, _Alloc>&, std::vector<_Tp, _Alloc>&)
     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
     ^
/usr/include/c++/4.8/bits/stl_vector.h:1451:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::vector<_Tp, _Alloc>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/vector:65:0,
                 from /usr/include/c++/4.8/queue:61,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_bvector.h:112:3: note: void std::swap(std::_Bit_reference, std::_Bit_reference)
   swap(_Bit_reference __x, _Bit_reference __y) noexcept
   ^
/usr/include/c++/4.8/bits/stl_bvector.h:112:3: note:   no known conversion for argument 1 from ‘int’ to ‘std::_Bit_reference’
/usr/include/c++/4.8/bits/stl_bvector.h:120:3: note: void std::swap(std::_Bit_reference, bool&)
   swap(_Bit_reference __x, bool& __y) noexcept
   ^
/usr/include/c++/4.8/bits/stl_bvector.h:120:3: note:   no known conversion for argument 1 from ‘int’ to ‘std::_Bit_reference’
/usr/include/c++/4.8/bits/stl_bvector.h:128:3: note: void std::swap(bool&, std::_Bit_reference)
   swap(bool& __x, _Bit_reference __y) noexcept
   ^
/usr/include/c++/4.8/bits/stl_bvector.h:128:3: note:   no known conversion for argument 1 from ‘int’ to ‘bool&’
In file included from /usr/include/c++/4.8/queue:64:0,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_queue.h:316:5: note: template<class _Tp, class _Seq> void std::swap(std::queue<_Tp, _Seq>&, std::queue<_Tp, _Seq>&)
     swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
     ^
/usr/include/c++/4.8/bits/stl_queue.h:316:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::queue<_Tp, _Seq>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/queue:64:0,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_queue.h:555:5: note: template<class _Tp, class _Sequence, class _Compare> void std::swap(std::priority_queue<_Tp, _Sequence, _Compare>&, std::priority_queue<_Tp, _Sequence, _Compare>&)
     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
     ^
/usr/include/c++/4.8/bits/stl_queue.h:555:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::priority_queue<_Tp, _Sequence, _Compare>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/tuple:39:0,
                 from /usr/include/c++/4.8/functional:55,
                 from /usr/include/c++/4.8/bits/stl_algo.h:66,
                 from /usr/include/c++/4.8/algorithm:62,
                 from prog.cpp:3:
/usr/include/c++/4.8/array:262:5: note: template<class _Tp, unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
     ^
/usr/include/c++/4.8/array:262:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::array<_Tp, _Nm>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/functional:55:0,
                 from /usr/include/c++/4.8/bits/stl_algo.h:66,
                 from /usr/include/c++/4.8/algorithm:62,
                 from prog.cpp:3:
/usr/include/c++/4.8/tuple:1048:5: note: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&)
     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
     ^
/usr/include/c++/4.8/tuple:1048:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::tuple<_Elements ...>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
In file included from /usr/include/c++/4.8/bits/stl_algo.h:66:0,
                 from /usr/include/c++/4.8/algorithm:62,
                 from prog.cpp:3:
/usr/include/c++/4.8/functional:2570:5: note: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)
     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
     ^
/usr/include/c++/4.8/functional:2570:5: note:   template argument deduction/substitution failed:
prog.cpp:64:12: note:   mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘int’
  swap(x1,y1); swap(x2,y2);
            ^
prog.cpp:65:19: error: invalid conversion from ‘double (*)(double)throw ()’ to ‘int’ [-fpermissive]
  bfs(0,x1,y1,w1,h1);
                   ^
prog.cpp:24:6: error:   initializing argument 3 of ‘void bfs(int, int, int, int, int)’ [-fpermissive]
 void bfs(int i,int x,int y,int w,int h)
      ^
stdout
Standard output is empty