Submission #791853

#TimeUsernameProblemLanguageResultExecution timeMemory
791853PiokemonAwesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
69 ms5324 KiB
#include <bits/stdc++.h> using namespace std; int odw[509][509]; string kier[509]; constexpr int oo = 1073741824; //NESWX int d[4][4][3] = {{{-1,0,0},{0,1,1},{1,0,2},{0,-1,3}}, {{-1,0,3},{0,1,0},{1,0,1},{0,-1,2}}, {{-1,0,2},{0,1,3},{1,0,0},{0,-1,1}}, {{-1,0,1},{0,1,2},{1,0,3},{0,-1,0}}}; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m,x,y,koszt,strona; string sciana(509,'X'); cin >> n >> m; kier[0] = sciana; kier[n+1] = sciana; for (int i=1;i<=n;i++){ cin >> kier[i]; kier[i] = 'X' + kier[i] + 'X'; } for( int i =0;i<=n+1;i++){ for (int j=0;j<=m+1;j++){ odw[i][j] = oo; } } priority_queue< pair<int,pair<int,int>> ,vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>> > dijks; dijks.push({0,{1,1}}); odw[1][1] = 0; pair<int,pair<int,int>> temp; while(!dijks.empty()){ temp = dijks.top(); koszt = temp.first; x = temp.second.first; y = temp.second.second; dijks.pop(); if (kier[x][y] == 'N'){ strona = 0; } if (kier[x][y] == 'E'){ strona = 1; } if (kier[x][y] == 'S'){ strona = 2; } if (kier[x][y] == 'W'){ strona = 3; } if (kier[x][y] == 'X'){ continue; } for (int i=0;i<4;i++){ if (odw[x + d[strona][i][0]][y + d[strona][i][1]] > odw[x][y] + d[strona][i][2]){ odw[x + d[strona][i][0]][y + d[strona][i][1]] = odw[x][y] + d[strona][i][2]; dijks.push({odw[x][y] + d[strona][i][2],{x + d[strona][i][0],y + d[strona][i][1]}}); } } } if (odw[n][m] == oo){ cout << "-1\n"; } else{ cout << odw[n][m] << "\n"; } return 0; }

Compilation message (stderr)

adventure.cpp: In function 'int main()':
adventure.cpp:17:17: warning: variable 'koszt' set but not used [-Wunused-but-set-variable]
   17 |     int n,m,x,y,koszt,strona;
      |                 ^~~~~
adventure.cpp:17:23: warning: 'strona' may be used uninitialized in this function [-Wmaybe-uninitialized]
   17 |     int n,m,x,y,koszt,strona;
      |                       ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...