Submission #836002

#TimeUsernameProblemLanguageResultExecution timeMemory
836002cnasteaAwesome Arrowland Adventure (eJOI19_adventure)C++14
100 / 100
199 ms30728 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; char t; vector<pair<int, int>> a[n*m]; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ cin >> t; if(t == 'N'){ if(j < m-1) a[i*m+j].push_back({i*m+j+1, 1}); if(i < n-1) a[i*m+j].push_back({(i+1)*m+j, 2}); if(j > 0) a[i*m+j].push_back({i*m+j-1, 3}); if(i > 0) a[i*m+j].push_back({(i-1)*m+j, 0}); } if(t == 'E'){ if(j < m-1) a[i*m+j].push_back({i*m+j+1, 0}); if(i < n-1) a[i*m+j].push_back({(i+1)*m+j, 1}); if(j > 0) a[i*m+j].push_back({i*m+j-1, 2}); if(i > 0) a[i*m+j].push_back({(i-1)*m+j, 3}); } if(t == 'S'){ if(j < m-1) a[i*m+j].push_back({i*m+j+1, 3}); if(i < n-1) a[i*m+j].push_back({(i+1)*m+j, 0}); if(j > 0) a[i*m+j].push_back({i*m+j-1, 1}); if(i > 0) a[i*m+j].push_back({(i-1)*m+j, 2}); } if(t == 'W'){ if(j < m-1) a[i*m+j].push_back({i*m+j+1, 2}); if(i < n-1) a[i*m+j].push_back({(i+1)*m+j, 3}); if(j > 0) a[i*m+j].push_back({i*m+j-1, 0}); if(i > 0) a[i*m+j].push_back({(i-1)*m+j, 1}); } } } int d[n*m]; multiset<pair<int, int>> s; for(int i = 1; i < n*m; i++){ d[i] = 1e9; s.insert({1e9, i}); } s.insert({0, 0}); d[0] = 0; while(s.size() > 0){ pair<int, int> p = *s.begin(); int v = p.second; s.erase(p); for(int i = 0; i < a[v].size(); i++){ if(d[v] + a[v][i].second < d[a[v][i].first]){ s.erase({d[a[v][i].first], a[v][i].first}); d[a[v][i].first] = d[v] + a[v][i].second; s.insert({d[a[v][i].first], a[v][i].first}); } } } if(d[m*n-1] == 1e9) cout << -1; else cout << d[m*n-1]; }

Compilation message (stderr)

adventure.cpp: In function 'int main()':
adventure.cpp:50:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int i = 0; i < a[v].size(); i++){
      |                        ~~^~~~~~~~~~~~~
#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...