#include <cstdio> #include <iostream> #include <queue> #include <vector> #include <map> #include <set> using namespace std; int main() { int xn, yn, pn; int mod = 2001; scanf("%d%d%d",&xn,&yn,&pn); char t[xn][yn], c; int dirX[] = {1, 0, -1, 0}; int dirY[] = {0, 1, 0, -1}; map<int, int> m; scanf("%c",&c); for (int i=0; i<xn; i++) { for (int j=0; j<yn; j++) scanf("%c",&t[i][j]); scanf("%c",&c); } queue<int> q; q.push(0); m[0] = 0; t[0][0]='V'; while (true) { int v = q.front(); q.pop(); int x = v/mod; int y = v%mod; //printf("%d %d %d\n",v,x,y); if (x == xn-1 && y == yn-1) break; for (int i=0; i<4; i++) { int nextX = x + dirX[i]; int nextY = y + dirY[i]; if (nextX >= 0 && nextY >= 0 && nextX < xn && nextY < yn && t[nextX][nextY] == '.') { m[nextX*mod+nextY] = m[x*mod+y]+1; t[nextX][nextY] = 'V'; q.push(nextX*mod+nextY); } } } long long int dist = m[(xn-1)*mod+yn-1]; long long int down = (dist - (xn - 1 + yn - 1)) / 2; long long int up = dist - down; //printf("dist: %d, down: %d, up: %d\n", dist, up, down); long long int minTime = -1; int winners = 0; long long int upTime, downTime; for (int i=0; i<pn; i++) { scanf("%lld%lld",&upTime,&downTime); long long int time = up*upTime + down*downTime; if (time == minTime) winners++; if (time < minTime || minTime == -1) { minTime = time; winners = 1; } } cout << minTime << " " << winners << endl; }
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 | #include <cstdio> #include <iostream> #include <queue> #include <vector> #include <map> #include <set> using namespace std; int main() { int xn, yn, pn; int mod = 2001; scanf("%d%d%d",&xn,&yn,&pn); char t[xn][yn], c; int dirX[] = {1, 0, -1, 0}; int dirY[] = {0, 1, 0, -1}; map<int, int> m; scanf("%c",&c); for (int i=0; i<xn; i++) { for (int j=0; j<yn; j++) scanf("%c",&t[i][j]); scanf("%c",&c); } queue<int> q; q.push(0); m[0] = 0; t[0][0]='V'; while (true) { int v = q.front(); q.pop(); int x = v/mod; int y = v%mod; //printf("%d %d %d\n",v,x,y); if (x == xn-1 && y == yn-1) break; for (int i=0; i<4; i++) { int nextX = x + dirX[i]; int nextY = y + dirY[i]; if (nextX >= 0 && nextY >= 0 && nextX < xn && nextY < yn && t[nextX][nextY] == '.') { m[nextX*mod+nextY] = m[x*mod+y]+1; t[nextX][nextY] = 'V'; q.push(nextX*mod+nextY); } } } long long int dist = m[(xn-1)*mod+yn-1]; long long int down = (dist - (xn - 1 + yn - 1)) / 2; long long int up = dist - down; //printf("dist: %d, down: %d, up: %d\n", dist, up, down); long long int minTime = -1; int winners = 0; long long int upTime, downTime; for (int i=0; i<pn; i++) { scanf("%lld%lld",&upTime,&downTime); long long int time = up*upTime + down*downTime; if (time == minTime) winners++; if (time < minTime || minTime == -1) { minTime = time; winners = 1; } } cout << minTime << " " << winners << endl; } |