Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define x first
- #define y second
- #define mp make_pair
- using namespace std;
- typedef pair<int,int> pii;
- typedef pair<int,pii> piii;
- const int inf = 11234567;
- int dx[] = {1,-1,0,0};
- int dy[] = {0,0,1,-1};
- const int NN = 1123;
- string ch[NN];
- int d[NN][NN];
- pii st,en;
- int n,m,v;
- bool pt(int x,int y){
- if (x >= n or y >= m or x < 0 or y < 0) return false;
- return true;
- }
- bool valid(){
- priority_queue<piii,vector<piii>,greater<piii> > pq;
- pq.push(mp(0,st));
- d[st.x][st.y] = 0;
- while(!pq.empty()){
- pii cur = pq.top().y;
- int dist = pq.top().x;
- pq.pop();
- if (cur == en) return true;
- if (d[cur.x][cur.y] < dist) continue;
- for(int i = 0; i < 4; ++i){
- int xx = cur.x + dx[i];
- int yy = cur.y + dy[i];
- if (!pt(xx,yy)) continue;
- int dd = d[cur.x][cur.y] + 1;
- if (dd > v) continue;
- if (ch[xx][yy] == 'F') dd = 0;
- if (d[xx][yy] > dd){
- d[xx][yy] = dd;
- pq.push(mp(dd,mp(xx,yy)));
- }
- }
- }
- return false;
- }
- void solve(){
- cin >> n >> m >> v;
- cin >> st.x >> st.y >> en.x >> en.y;
- st.x--,st.y--,en.x--,en.y--;
- for(int i = 0; i < n; ++i){
- cin >> ch[i];
- for(int j = 0; j < m; ++j)
- d[i][j] = inf;
- }
- if (valid()) cout << "Hello, Deimos!\n";
- else cout << "Dire victory\n";
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement