제출 #466228

#제출 시각아이디문제언어결과실행 시간메모리
466228NintsiChkhaidzeAwesome Arrowland Adventure (eJOI19_adventure)C++14
34 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pi pair<int,int> #define s second #define f first #define left (h<<1),l,((l+r)>>1) #define right ((h<<1)|1),((l+r)>>1) + 1,r #define int ll using namespace std; char A[505][505]; int dp[505][505],n,m; bool f[505][505]; vector <char> v = {'N','E','S','W'}; int go(char x,char y){ if (x == 'X') return 1e9; int lf = -1,rg = -1; for (int i = 0; i < v.size(); i++){ if (v[i] == x) lf = i; if (v[i] == y) rg = i; } if (lf <= rg) return rg - lf; return 4 - lf + rg; } int get(int x,int y){ if (x < 0 || x >= n || y < 0 || y >= m) return 1e9; if (dp[x][y] != -1) return dp[x][y]; if (f[x][y]) return 1e9; f[x][y] = 1; int a = get(x - 1,y) + go(A[x - 1][y],'S'); int b = get(x + 1,y) + go(A[x + 1][y],'N'); int c = get(x,y - 1) + go(A[x][y - 1],'E'); int d = get(x,y + 1) + go(A[x][y + 1],'W'); return dp[x][y] = min({a,b,c,d}); } void G(int x,int y){ if (x < 0 || x >= n || y < 0 || y >= m || dp[x][y] == 0) return; dp[x][y] = 0; if (A[x][y] == 'N') G(x-1,y); if (A[x][y] == 'S') G(x+1,y); if (A[x][y] == 'E') G(x,y+1); if (A[x][y] == 'W') G(x,y-1); } signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); cin>>n>>m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> A[i][j],dp[i][j] = -1; G(0,0); ll ans = get(n - 1,m - 1); if (ans >= 1e9) cout<<-1; else cout<<ans; }

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

adventure.cpp: In function 'long long int go(char, char)':
adventure.cpp:22:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 0; i < 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...