제출 #549669

#제출 시각아이디문제언어결과실행 시간메모리
549669Danilo21Awesome Arrowland Adventure (eJOI19_adventure)C++14
100 / 100
85 ms7868 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define en '\n' #define sp ' ' #define tb '\t' #define ri(n) int n; cin >> n #define rl(n) ll n; cin >> n #define rs(s) string s; cin >> s #define rc(c) char c; cin >> c #define rv(v) for (auto &x : v) cin >> x #define pven(v) for (auto x : v) cout << x << en #define pv(v) for (auto x : v) cout << x << sp; cout << en #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define yes cout << "YES" << en #define no cout << "NO" << en #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) #define ssort(a, b) if (a < b) swap(a, b) #define bitcnt(a) __builtin_popcountll(a) #define bithigh(a) 63-__builtin_clzll(a) #define lg bithigh ll highpow(ll a) { return 1LL << (ll)lg(a); } using namespace std; const ll LINF = 4e18; const int mxN = 5e2+10, INF = 2e9, mod = (1 ? 1e9+7 : 998244353); ll n, m, a[mxN][mxN], dist[mxN][mxN]; bool vis[mxN][mxN]; int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; bool Valid(int i, int j){ return i >= 0 && i < n && j >= 0 && j < m; } void Solve(){ cin >> n >> m; for (int i = 0; i < n; i++){ rs(s); for (int j = 0; j < m; j++){ if (s[j]=='X') a[i][j] = 0; if (s[j]=='N') a[i][j] = 1; if (s[j]=='E') a[i][j] = 2; if (s[j]=='S') a[i][j] = 3; if (s[j]=='W') a[i][j] = 4; } } for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) dist[i][j] = INF; priority_queue<array<int, 3>, vector<array<int, 3> >, greater<array<int, 3> > > pq; dist[0][0] = 0; pq.push({0, 0 ,0}); while (pq.size()){ auto [d, i, j] = pq.top(); pq.pop(); if (vis[i][j]) continue; vis[i][j] = 1; if (!a[i][j]) continue; for (int t = 0; t < 4; t++){ int x = (a[i][j] + t - 1) % 4; int _i = i + dx[x], _j = j + dy[x]; if (Valid(_i, _j) && dist[i][j] + t < dist[_i][_j]){ dist[_i][_j] = dist[i][j] + t; pq.push({dist[_i][_j], _i, _j}); } } } cout << (dist[n-1][m-1]^INF ? dist[n-1][m-1] : -1) << en; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); cout << setprecision(12) << fixed; cerr << setprecision(12) << fixed; cerr << "Started!" << endl; int t = 1; //cin >> t; while (t--) Solve(); return 0; }

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

adventure.cpp: In function 'long long int highpow(long long int)':
adventure.cpp:26:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   26 | #define bithigh(a) 63-__builtin_clzll(a)
      |                      ^
adventure.cpp:27:12: note: in expansion of macro 'bithigh'
   27 | #define lg bithigh
      |            ^~~~~~~
adventure.cpp:28:38: note: in expansion of macro 'lg'
   28 | ll highpow(ll a) { return 1LL << (ll)lg(a); }
      |                                      ^~
adventure.cpp: In function 'void Solve()':
adventure.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         auto [d, i, j] = pq.top(); pq.pop();
      |              ^
adventure.cpp:71:37: warning: narrowing conversion of 'dist[_i][_j]' from 'long long int' to 'int' [-Wnarrowing]
   71 |                 pq.push({dist[_i][_j], _i, _j});
      |                          ~~~~~~~~~~~^
#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...