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
#include <cstdio>
#include <queue>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair
#define FT first
#define SD second
#define INT(x) int x; scanf("%d", &x)

typedef long long LL;
typedef pair<int,int> PII;

const int INF = 1000000000;
const LL INFLL = 1000000000000000000LL;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};
char a[2000][2001];
int d[2000][2000];

int main() {
	INT(n);
	INT(m);
	INT(k);
	REP(i,n) scanf("%s", a[i]);
	REP(i,n) REP(j,m) d[i][j] = INF;
	queue<PII> q;
	d[0][0] = 0;
	q.push(MP(0, 0));
	while (!q.empty()) {
		PII p = q.front();
		q.pop();
		REP(dd,4) {
			int x = p.FT + DX[dd];
			int y = p.SD + DY[dd];
			if (x < 0 || y < 0 || x >= n || y >= m) continue;
			if (a[x][y] == 'X') continue;
			if (d[x][y] != INF) continue;
			d[x][y] = d[p.FT][p.SD] + 1;
			q.push(MP(x, y));
		}
	}
	int r = d[n - 1][m - 1];
	int o = n + m - 2;
	LL down = (r - o) >> 1;
	LL up = r - down;
	LL best = INFLL;
	int c = 0;
	REP(kk,k) {
		INT(a);
		INT(b);
		LL x = a * up + b * down;
		if (x < best) {
			best = x;
			c = 1;
		} else if (x == best) ++c;
	}
	printf("%lld %d\n", best, c);
}