#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e;
bool odw[2007][2007];
int odlg[2007][2007];
priority_queue < pair <int, pair <int, int> > > Q;
pair <int, pair <int, int> > p;
void Dijkstra()
{
for(int i = 0; i < a; i++)
{
for(int x = 0; x < b; x++)
{
odlg[i][x] = 2000000000;
}
}
Q.push(make_pair(0, make_pair(0, 0)));
while(Q.size() != 0)
{
p = Q.top();
Q.pop();
if(-p.first > odlg[p.second.first][p.second.second])
{
continue;
}
odlg[p.second.first][p.second.second] = -p.first;
if(p.second.first > 0 && odw[p.second.first - 1][p.second.second] == 0 && odlg[p.second.first][p.second.second] + e < odlg[p.second.first - 1][p.second.second])
{
Q.push(make_pair(-(odlg[p.second.first][p.second.second] + e), make_pair(p.second.first - 1, p.second.second)));
}
if(p.second.first < a - 1 && odw[p.second.first + 1][p.second.second] == 0 && odlg[p.second.first][p.second.second] + d < odlg[p.second.first + 1][p.second.second])
{
Q.push(make_pair(-(odlg[p.second.first][p.second.second] + d), make_pair(p.second.first + 1, p.second.second)));
}
if(p.second.second > 0 && odw[p.second.first][p.second.second - 1] == 0 && odlg[p.second.first][p.second.second] + e < odlg[p.second.first][p.second.second - 1])
{
Q.push(make_pair(-(odlg[p.second.first][p.second.second] + e), make_pair(p.second.first, p.second.second - 1)));
}
if(p.second.second < b - 1 && odw[p.second.first][p.second.second + 1] == 0 && odlg[p.second.first][p.second.second] + d < odlg[p.second.first][p.second.second + 1])
{
Q.push(make_pair(-(odlg[p.second.first][p.second.second] + d), make_pair(p.second.first, p.second.second + 1)));
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b >> c;
char h;
for(int i = 0; i < a; i++)
{
for(int x = 0; x < b; x++)
{
cin >> h;
if(h == 'X')
{
odw[i][x] = 1;
}
}
}
cin >> d >> e;
Dijkstra();
cout << odlg[a - 1][b - 1] << " 1" << endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <bits/stdc++.h> using namespace std; int a, b, c, d, e; bool odw[2007][2007]; int odlg[2007][2007]; priority_queue < pair <int, pair <int, int> > > Q; pair <int, pair <int, int> > p; void Dijkstra() { for(int i = 0; i < a; i++) { for(int x = 0; x < b; x++) { odlg[i][x] = 2000000000; } } Q.push(make_pair(0, make_pair(0, 0))); while(Q.size() != 0) { p = Q.top(); Q.pop(); if(-p.first > odlg[p.second.first][p.second.second]) { continue; } odlg[p.second.first][p.second.second] = -p.first; if(p.second.first > 0 && odw[p.second.first - 1][p.second.second] == 0 && odlg[p.second.first][p.second.second] + e < odlg[p.second.first - 1][p.second.second]) { Q.push(make_pair(-(odlg[p.second.first][p.second.second] + e), make_pair(p.second.first - 1, p.second.second))); } if(p.second.first < a - 1 && odw[p.second.first + 1][p.second.second] == 0 && odlg[p.second.first][p.second.second] + d < odlg[p.second.first + 1][p.second.second]) { Q.push(make_pair(-(odlg[p.second.first][p.second.second] + d), make_pair(p.second.first + 1, p.second.second))); } if(p.second.second > 0 && odw[p.second.first][p.second.second - 1] == 0 && odlg[p.second.first][p.second.second] + e < odlg[p.second.first][p.second.second - 1]) { Q.push(make_pair(-(odlg[p.second.first][p.second.second] + e), make_pair(p.second.first, p.second.second - 1))); } if(p.second.second < b - 1 && odw[p.second.first][p.second.second + 1] == 0 && odlg[p.second.first][p.second.second] + d < odlg[p.second.first][p.second.second + 1]) { Q.push(make_pair(-(odlg[p.second.first][p.second.second] + d), make_pair(p.second.first, p.second.second + 1))); } } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b >> c; char h; for(int i = 0; i < a; i++) { for(int x = 0; x < b; x++) { cin >> h; if(h == 'X') { odw[i][x] = 1; } } } cin >> d >> e; Dijkstra(); cout << odlg[a - 1][b - 1] << " 1" << endl; return 0; } |
English