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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int MAXN = 2003, MAXK = 1e6 + 6;
char tab[MAXN][MAXN];
int dist[MAXN][MAXN];
ll ans[MAXK];
ll n, m, k;

typedef pair<pair<ll,int>,int> P;
#define f first.first
#define s first.second
#define t second
priority_queue <P> Q;
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

ll dijkstra(int x, int y)
{
	dist[x][y] = 0;
	Q.push({{0,x},y});
	while(!Q.empty())
	{
		x = Q.top().s, y = Q.top().t;
		ll v = -Q.top().f;
		Q.pop();
		for(int i = 0; i < 4; i++)
		{
			int X = x + dx[i], Y = y + dy[i], d = (X < x || Y < y) ? 1 : 0;
			if(tab[X][Y] == '.' && v + d < dist[X][Y])
			{
				dist[X][Y] = v + d;
				Q.push({{-dist[X][Y],X},Y});
			}
		}
	}
	return dist[n][m];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> k;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> tab[i][j], dist[i][j] = INT_MAX;
	ll x = dijkstra(1,1);
	ll mx = LLONG_MAX;
	for(int i = 1; i <= k; i++)
	{
		ll a, b;
		cin >> a >> b;
		ans[i] = (n+m-2)*a + x*(a+b);
		mx = min(mx,ans[i]);
	}
	int r = 0;
	for(int i = 1; i <= k; i++)
		if(ans[i] == mx) r++;
	cout << mx << " " << r;
	return 0;
}