제출 #448350

#제출 시각아이디문제언어결과실행 시간메모리
448350bigoAwesome Arrowland Adventure (eJOI19_adventure)C++14
34 / 100
2 ms332 KiB
#include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; const ll sz = 1e6; const ll INF = 1e18; ll n, m; #define pii pair<ll,ll> vector<vector<pii>>gra; vector<ll> dist; bitset<sz>done; void solve(ll su) { for (ll i = 0; i < n*m; i++) { dist[i] = INF; } dist[su] = 0; priority_queue<pii, vector<pii>, greater<pii>>pq; pq.push({ 0,su }); while (!pq.empty()) { pii tmp = pq.top(); pq.pop(); ll u = tmp.second, d = tmp.first; if (done[u]) continue; done[u] = true; for (auto ii : gra[tmp.second]) { ll v = ii.first, w = ii.second; if (dist[v] > dist[u] + w) { dist[v] = dist[u] + w; pq.push({ dist[v],v }); } } } } int main() { cin >> n >> m; vector<vector<char>>vec1(n, vector<char>(m)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { cin >> vec1[i][j]; } } vector<vector<ll>>vec(n, vector<ll>(m)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { if (vec1[i][j] == 'N') vec[i][j] = 1; if (vec1[i][j] == 'E') vec[i][j] = 2; if (vec1[i][j] == 'S') vec[i][j] = 3; if (vec1[i][j] == 'W') vec[i][j] = 4; } } ll tmp = 0; dist.resize(n * m); gra.resize(n * m); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { if (vec1[i][j] != 'X') { if (i != 0) { gra[tmp].push_back({ tmp - m,vec[i][j] - 1 }); } if (i != n - 1) { if (vec[i][j] > 3) gra[tmp].push_back({ tmp + m,4 - (vec[i][j] - 3) }); else gra[tmp].push_back({ tmp + m,3 - vec[i][j] }); } if (j != m - 1) { if (vec[i][j] > 2) gra[tmp].push_back({ tmp + 1,4 - (vec[i][j] - 2) }); else gra[tmp].push_back({ tmp + 1,2 - vec[i][j] }); } if (j != 0) { gra[tmp].push_back({ tmp - 1 ,4 - vec[i][j] }); } } tmp++; } } solve(0); if (dist[n * m - 1] == INF) cout << -1; else cout << dist[n * m - 1]; }

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

adventure.cpp: In function 'void solve(ll)':
adventure.cpp:22:22: warning: unused variable 'd' [-Wunused-variable]
   22 |   ll u = tmp.second, d = tmp.first;
      |                      ^
#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...