제출 #769469

#제출 시각아이디문제언어결과실행 시간메모리
769469GordonRemzi007Awesome Arrowland Adventure (eJOI19_adventure)C++17
100 / 100
71 ms5696 KiB
#include <iostream> #include <vector> #include <queue> #include <climits> using namespace std; int n, m, val; string str; pair<int,int> y; pair<int, pair<int,int>> x; priority_queue<pair<int, pair<int,int>>> pq; vector<pair<int,int>> dir = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} }; int main() { cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)), path(n, vector<int>(m, INT_MAX)); for(int i = 0; i < n; i++) { cin >> str; for(int j = 0; j < m; j++) { switch(str[j]) { case 'N': a[i][j] = 3; break; case 'E': a[i][j] = 0; break; case 'S': a[i][j] = 1; break; case 'W': a[i][j] = 2; break; default: a[i][j] = -1; break; } } } if(a[0][0] != -1) pq.push({0, {0, 0}}); while(pq.size()) { x = pq.top(); pq.pop(); x.first = -x.first; if(x.first >= path[x.second.first][x.second.second]) continue; //cout << x.first << " " << x.second.first << " " << x.second.second << "\n"; path[x.second.first][x.second.second] = x.first; for(int i = 0; i < dir.size(); i++) { y = x.second; y.first+=dir[i].first; y.second+=dir[i].second; if(y.first < 0 || y.first > n-1 || y.second < 0 || y.second > m-1 || (a[y.first][y.second] == -1 && (y.first != n-1 || y.second != m-1))) continue; val = (4-a[x.second.first][x.second.second]+i)%4; //cout << "VAL " << val << " " << a[x.second.first][x.second.second] << " " << i << "\n"; if(path[x.second.first][x.second.second]+val < path[y.first][y.second]) pq.push({-(path[x.second.first][x.second.second]+val), y}); } } if(path[n-1][m-1] == INT_MAX) cout << "-1\n"; else cout << path[n-1][m-1] << "\n"; }

컴파일 시 표준 에러 (stderr) 메시지

adventure.cpp: In function 'int main()':
adventure.cpp:53: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]
   53 |         for(int i = 0; i < dir.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...