Submission #750382

#TimeUsernameProblemLanguageResultExecution timeMemory
750382MrM7mdAwesome Arrowland Adventure (eJOI19_adventure)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define F first #define S second #define pb push_back #define all(a) a.begin(),a.end() const int N=3e5; const int off=(1<<18); const int MOD = 1e9+7; vector<vector<int>>gr(N); int val[N],vis[N]; map<pair<int,int>,int>mp; void dij(int a){ // vis[a]=1; val[a]=0; priority_queue<pair<int,int>>pq; pq.push({0,a}); while(!pq.empty()){ int vl=pq.top().F,x=pq.top().S; if(vis[a])continue; pq.pop(); vis[it]=1; // cout<<vl<<' '<<x<<endl; for(auto it:gr[x]){ if(val[it]>val[x]+mp[{x,it}]) val[it]=val[x]+mp[{x,it}]; pq.push({val[it]*-1,it}); } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> m >> n; char ch[m][n]; for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ cin >> ch[i][j]; } } for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ val[n*i+j]=1e9; if(ch[i][j]=='X'){ vis[n*i+j]=1; continue; } if(i){ gr[n*i+j].pb(n*(i-1)+j); if(ch[i][j]=='E')mp[{n*i+j,n*(i-1)+j}]=3; if(ch[i][j]=='W')mp[{n*i+j,n*(i-1)+j}]=1; if(ch[i][j]=='N')mp[{n*i+j,n*(i-1)+j}]=0; if(ch[i][j]=='S')mp[{n*i+j,n*(i-1)+j}]=2; } if(i<m-1){ gr[n*i+j].pb(n*(i+1)+j); if(ch[i][j]=='E')mp[{n*i+j,n*(i+1)+j}]=1; if(ch[i][j]=='W')mp[{n*i+j,n*(i+1)+j}]=3; if(ch[i][j]=='N')mp[{n*i+j,n*(i+1)+j}]=2; if(ch[i][j]=='S')mp[{n*i+j,n*(i+1)+j}]=0; } if(j){ gr[n*i+j].pb(n*i+j-1); if(ch[i][j]=='E')mp[{n*i+j,n*i+j-1}]=2; if(ch[i][j]=='W')mp[{n*i+j,n*i+j-1}]=0; if(ch[i][j]=='N')mp[{n*i+j,n*i+j-1}]=3; if(ch[i][j]=='S')mp[{n*i+j,n*i+j-1}]=1; } if(j<n-1){ gr[n*i+j].pb(n*i+j+1); if(ch[i][j]=='E')mp[{n*i+j,n*i+j+1}]=0; if(ch[i][j]=='W')mp[{n*i+j,n*i+j+1}]=2; if(ch[i][j]=='N')mp[{n*i+j,n*i+j+1}]=1; if(ch[i][j]=='S')mp[{n*i+j,n*i+j+1}]=3; } } } dij(0); int lst=(n)*(m)-1; if(val[lst]==1e9)val[lst]=-1; cout<<val[lst]; }

Compilation message (stderr)

adventure.cpp: In function 'void dij(long long int)':
adventure.cpp:25:11: error: 'it' was not declared in this scope; did you mean 'int'?
   25 |       vis[it]=1;
      |           ^~
      |           int
adventure.cpp:22:11: warning: unused variable 'vl' [-Wunused-variable]
   22 |       int vl=pq.top().F,x=pq.top().S;
      |           ^~