#include <bits/stdc++.h> using namespace std; #define mp make_pair char tab[2004][2004]; long long odl[2004][2004]; priority_queue <pair <long long, pair<long long,long long> > > q; long long n,m,k; long long h,wyn=1e9,il,a,b; void dijkstra() { odl[1][1]=0; q.push(mp(0,mp(1,1))); while(!q.empty()) { long long o=-q.top().first, f=q.top().second.first, s=q.top().second.second; q.pop(); if(o>odl[f][s]) continue; if(tab[f-1][s]!='X' && odl[f-1][s]>o+1) { q.push(mp(-o-1,mp(f-1,s))); odl[f-1][s]=o+1; } if(tab[f+1][s]!='X' && odl[f+1][s]>o+1) { q.push(mp(-o-1,mp(f+1,s))); odl[f+1][s]=o+1; } if(tab[f][s-1]!='X' && odl[f][s-1]>o+1) { q.push(mp(-o-1,mp(f,s-1))); odl[f][s-1]=o+1; } if(tab[f][s+1]!='X' && odl[f][s+1]>o+1) { q.push(mp(-o-1,mp(f,s+1))); odl[f][s+1]=o+1; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); wyn*=wyn; cin>>n>>m>>k; h=n+m-2; for(long long i=0;i<=2002;i++) { for(long long j=0;j<=2002;j++) { odl[i][j]=1e9; odl[i][j]*=odl[i][j]; tab[i][j]='X'; } } for(long long i=1;i<=n;i++) { for(long long j=1;j<=m;j++) { cin>>tab[i][j]; } } dijkstra(); odl[n][m]-=h; odl[n][m]/=2; for(long long i=1;i<=k;i++) { cin>>a>>b; long long p=h*a+(odl[n][m]*(a+b)); if(p==wyn) il++; if(p<wyn) { wyn=p; il=1; } } cout<<wyn<<' '<<il<<'\n'; 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 | #include <bits/stdc++.h> using namespace std; #define mp make_pair char tab[2004][2004]; long long odl[2004][2004]; priority_queue <pair <long long, pair<long long,long long> > > q; long long n,m,k; long long h,wyn=1e9,il,a,b; void dijkstra() { odl[1][1]=0; q.push(mp(0,mp(1,1))); while(!q.empty()) { long long o=-q.top().first, f=q.top().second.first, s=q.top().second.second; q.pop(); if(o>odl[f][s]) continue; if(tab[f-1][s]!='X' && odl[f-1][s]>o+1) { q.push(mp(-o-1,mp(f-1,s))); odl[f-1][s]=o+1; } if(tab[f+1][s]!='X' && odl[f+1][s]>o+1) { q.push(mp(-o-1,mp(f+1,s))); odl[f+1][s]=o+1; } if(tab[f][s-1]!='X' && odl[f][s-1]>o+1) { q.push(mp(-o-1,mp(f,s-1))); odl[f][s-1]=o+1; } if(tab[f][s+1]!='X' && odl[f][s+1]>o+1) { q.push(mp(-o-1,mp(f,s+1))); odl[f][s+1]=o+1; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); wyn*=wyn; cin>>n>>m>>k; h=n+m-2; for(long long i=0;i<=2002;i++) { for(long long j=0;j<=2002;j++) { odl[i][j]=1e9; odl[i][j]*=odl[i][j]; tab[i][j]='X'; } } for(long long i=1;i<=n;i++) { for(long long j=1;j<=m;j++) { cin>>tab[i][j]; } } dijkstra(); odl[n][m]-=h; odl[n][m]/=2; for(long long i=1;i<=k;i++) { cin>>a>>b; long long p=h*a+(odl[n][m]*(a+b)); if(p==wyn) il++; if(p<wyn) { wyn=p; il=1; } } cout<<wyn<<' '<<il<<'\n'; return 0; } |