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
#include<cstdio>
#include<map>
#include<queue>
#include<utility>

int n, m, k;
long long a, b;
char map[2020][2020];
char row[2020];
int d[2020][2020];
int dir[4][2] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
std::map<long long, int> result;
std::queue<std::pair<int, int>> queue;

int get_shortest()
{
	d[1][1] = 1;
	queue.push(std::make_pair(1, 1));

	while (!queue.empty())
	{
		std::pair<int, int> next = queue.front(); queue.pop();

		for (int i = 0; i < 4; ++i)
		{
			if (map[next.first + dir[i][0]][next.second + dir[i][1]] == 'X' || d[next.first + dir[i][0]][next.second + dir[i][1]]) continue;
			if (next.first + dir[i][0] == n && next.second + dir[i][1] == m) return d[next.first][next.second];
			d[next.first + dir[i][0]][next.second + dir[i][1]] = d[next.first][next.second] + 1;
			queue.push(std::make_pair(next.first + dir[i][0], next.second + dir[i][1]));
		}
	}

}

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; ++i)
	{
		scanf("%s", row);
		for (int j = 0; j < m; ++j) map[i + 1][j + 1] = row[j];
	}
	for (int j = 0; j < m + 2; ++j) map[0][j] = map[n + 1][j] = 'X';
	for (int i = 0; i < n + 2; ++i) map[i][0] = map[i][m + 1] = 'X';

	int len_shortest = get_shortest();
	int down = (len_shortest - (n + m - 2)) / 2;
	int up = len_shortest - down;

	for (int i = 0; i < k; ++i)
	{
		scanf("%lld %lld", &a, &b);
		long long cost = a * up + b * down;
		if (result.find(cost) == result.end()) result[cost] = 1;
		else result[cost]++;
	}

	printf("%lld %d\n", result.begin()->first, result.begin()->second);

	return 0;
}