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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<bits/stdc++.h>
using namespace std;
int odw[2006][2006], tab[2006][2006];
long long a[2006][2006], b[2006][2006];
struct wsp{
	int a, b;
};
int ka, kb;
queue <wsp> q;
void bfs(int x, int y)
{
	wsp u;
	u.a=x;
	u.b=y;
	odw[x][y]=1;
	q.push(u);
	while(!q.empty())
	{
		wsp u=q.front();
		q.pop();
		x=u.a;
		y=u.b;
		if(odw[x-1][y]==0&&tab[x-1][y]==0)
		{
			odw[x-1][y]=1;
			a[x-1][y]=1+a[x][y];
			b[x-1][y]=b[x][y];
			wsp pom;
			pom.a=x-1;
			pom.b=y;
			q.push(pom);
		}
		if(odw[x][y-1]==0&&tab[x][y-1]==0)
		{
			odw[x][y-1]=1;
			a[x][y-1]=1+a[x][y];
			b[x][y-1]=b[x][y];
			wsp pom;
			pom.a=x;
			pom.b=y-1;
			q.push(pom);
		}
		if(odw[x+1][y]==0&&tab[x+1][y]==0)
		{
			odw[x+1][y]=1;
			a[x+1][y]=a[x][y];
			b[x+1][y]=1+b[x][y];
			wsp pom;
			pom.a=x+1;
			pom.b=y;
			q.push(pom);
		}
		if(odw[x][y+1]==0&&tab[x][y+1]==0)
		{
			odw[x][y+1]=1;
			a[x][y+1]=a[x][y];
			b[x][y+1]=1+b[x][y];
			wsp pom;
			pom.a=x;
			pom.b=y+1;
			q.push(pom);
		}
		
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m, q;
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)
	for(int j=1; j<=m; j++)
	{
		char c;
		cin>>c;
		if(c=='X')
		tab[i][j]=1;
	}
	for(int i=0;i<=n+1;i++)
	{
	for(int j=0;j<=m+1; j++)
	{
		if(i==0||i==n+1)
		tab[i][j]=1;
		if(j==0||j==m+1)
		tab[i][j]=1;
	//	printf("%d", tab[i][j]);
	}
//	printf("\n");
	}

	bfs(1,1);
	long long y1=a[n][m], x1=b[n][m];
//	printf("%lld %lld", y1, x1);
	long long maks=100000000000000000;
	int coun=0;
	for(int i=1; i<=q; i++)
	{
		long long aa, bb;
		cin>>aa>>bb;
		long long koszt=aa*x1+bb*y1;
		if(koszt<maks)
		{
			maks=koszt;
			coun=1;
		}
		else if(koszt==maks)
		coun++;
	}
cout<<maks<<" "<<coun;
	return 0;
}