Submission #1232821

#TimeUsernameProblemLanguageResultExecution timeMemory
1232821billylolwkwkAwesome Arrowland Adventure (eJOI19_adventure)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define vec vector #define pll pair<ll,ll> #define fr first #define sc second #define dbg(x) cout<<#x<<" = "<<x<<endl struct data{ ll x,y,dist; }; const vec<pll>off={{-1,0},{0,1},{1,0},{0,-1},{-1,0},{0,1},{1,0}}; const ll INF=LLONG_MAX; ll n,m; vec<vec<char>>g; vec<vec<ll>>d; bool chk(const ll x, const ll y){if(x<=0||x>n||y<=0||y>m)return false;return true;} struct com{ bool operator()(const data&a, const data&b){ return a.dist>b.dist; } }; priority_queue<data,vec<data>,com>pq; // Djikstra algorithm signed main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>m; g=vec<vec<char>>(n+1,vec<char>(m+1)); d=vec<vec<ll>>(n+1,vec<ll>(m+1,INF)); for(ll i=1;i<=n;i++)for(ll j=1;j<=m;j++)cin>>g[i][j]; pq.push({1,1,0}); while(!pq.empty()){ data cur=pq.top();pq.pop(); ll x=cur.x,y=cur.y,dist=cur.dist,offset; // Offset jika g[i][j]=='N' if(d[x][y]<=dist)continue;d[x][y]=dist; char dir=g[x][y];if(dir=='X')continue; // Ya gak usah dilanjutin if(dir=='N')offset=0; else if(dir=='E')offset=1; else if(dir=='S')offset=2; else if(dir='W')offset=3; for(ll i=offset;i<offset+4;i++){ ll xx=x+off[i].fr;ll yy=y+off[i].sc; // Pergi kesebelahnya if(!chk(xx,yy))continue; // Keluar dari map if(d[xx][yy]>dist+i-offset)pq.push({xx,yy,dist+i-offset}); } } if(d[n][m]==INF)cout<<-1;else cout<<d[n][m];return 0; }

Compilation message (stderr)

adventure.cpp:19:31: error: reference to 'data' is ambiguous
   19 |         bool operator()(const data&a, const data&b){
      |                               ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from adventure.cpp:1:
/usr/include/c++/11/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
adventure.cpp:9:8: note:                 'struct data'
    9 | struct data{
      |        ^~~~
adventure.cpp:19:45: error: reference to 'data' is ambiguous
   19 |         bool operator()(const data&a, const data&b){
      |                                             ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from adventure.cpp:1:
/usr/include/c++/11/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
adventure.cpp:9:8: note:                 'struct data'
    9 | struct data{
      |        ^~~~
adventure.cpp: In member function 'bool com::operator()(const int&, const int&)':
adventure.cpp:20:26: error: request for member 'dist' in 'a', which is of non-class type 'const int'
   20 |                 return a.dist>b.dist;
      |                          ^~~~
adventure.cpp:20:33: error: request for member 'dist' in 'b', which is of non-class type 'const int'
   20 |                 return a.dist>b.dist;
      |                                 ^~~~
adventure.cpp: At global scope:
adventure.cpp:23:29: error: template argument 1 is invalid
   23 | priority_queue<data,vec<data>,com>pq; // Djikstra algorithm
      |                             ^
adventure.cpp:23:29: error: template argument 2 is invalid
adventure.cpp:23:34: error: template argument 1 is invalid
   23 | priority_queue<data,vec<data>,com>pq; // Djikstra algorithm
      |                                  ^
adventure.cpp:23:34: error: template argument 2 is invalid
adventure.cpp: In function 'int main()':
adventure.cpp:30:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   30 |         pq.push({1,1,0});
      |            ^~~~
adventure.cpp:31:19: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   31 |         while(!pq.empty()){
      |                   ^~~~~
adventure.cpp:32:17: error: reference to 'data' is ambiguous
   32 |                 data cur=pq.top();pq.pop();
      |                 ^~~~
In file included from /usr/include/c++/11/string:54,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from adventure.cpp:1:
/usr/include/c++/11/bits/range_access.h:319:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(std::initializer_list<_Tp>)'
  319 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:310:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  310 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:300:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  300 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/11/bits/range_access.h:290:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  290 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
adventure.cpp:9:8: note:                 'struct data'
    9 | struct data{
      |        ^~~~
adventure.cpp:32:38: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   32 |                 data cur=pq.top();pq.pop();
      |                                      ^~~
adventure.cpp:33:22: error: 'cur' was not declared in this scope
   33 |                 ll x=cur.x,y=cur.y,dist=cur.dist,offset; // Offset jika g[i][j]=='N'
      |                      ^~~
adventure.cpp:34:25: error: 'y' was not declared in this scope
   34 |                 if(d[x][y]<=dist)continue;d[x][y]=dist;
      |                         ^
adventure.cpp:34:29: error: 'dist' was not declared in this scope
   34 |                 if(d[x][y]<=dist)continue;d[x][y]=dist;
      |                             ^~~~
adventure.cpp:34:48: error: 'y' was not declared in this scope
   34 |                 if(d[x][y]<=dist)continue;d[x][y]=dist;
      |                                                ^
adventure.cpp:34:51: error: 'dist' was not declared in this scope
   34 |                 if(d[x][y]<=dist)continue;d[x][y]=dist;
      |                                                   ^~~~
adventure.cpp:36:29: error: 'offset' was not declared in this scope; did you mean 'off_t'?
   36 |                 if(dir=='N')offset=0;
      |                             ^~~~~~
      |                             off_t
adventure.cpp:37:34: error: 'offset' was not declared in this scope; did you mean 'off_t'?
   37 |                 else if(dir=='E')offset=1;
      |                                  ^~~~~~
      |                                  off_t
adventure.cpp:38:34: error: 'offset' was not declared in this scope; did you mean 'off_t'?
   38 |                 else if(dir=='S')offset=2;
      |                                  ^~~~~~
      |                                  off_t
adventure.cpp:39:33: error: 'offset' was not declared in this scope; did you mean 'off_t'?
   39 |                 else if(dir='W')offset=3;
      |                                 ^~~~~~
      |                                 off_t
adventure.cpp:40:26: error: 'offset' was not declared in this scope; did you mean 'off_t'?
   40 |                 for(ll i=offset;i<offset+4;i++){
      |                          ^~~~~~
      |                          off_t
adventure.cpp:43:55: error: request for member 'push' in 'pq', which is of non-class type 'int'
   43 |                         if(d[xx][yy]>dist+i-offset)pq.push({xx,yy,dist+i-offset});
      |                                                       ^~~~