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

//vector <long long> v;

//stack <long long> s, s2;
//bbbbaaaa
queue <long long> s;

long long int  z[1], x[2001][2001], y[10], m, szu, wy[10][1];
char s1[1], s2[1], cc;

int war(const void*a, const void *b)
{
    if(*(long long*)a>*(long long*)b)return(1);
    return(0);
}

int main()
{
    long long int c, d, e, f, g, i, j, q, t, k, a, n, b, w, p;

    t=1;
    //scanf("%lld", &t);
    //for(q=1; q<=t; q++)
    {
        scanf("%lld%lld%lld", &n, &m, &t);

        for(i=0; i<n; i++)
        {
            for(j=0; j<m; j++)
            {
                scanf(" %c", &cc);
                if(cc=='X')x[i][j]=-1;
            }
        }

        s.push(0);

        while(s.size()>0)
        {
            a=s.front();
            s.pop();
            b=a%3000;
            a/=3000;

            e=x[a][b]+1;
            x[0][0]=-1;

            c=max(a-1, a-a);
            d=b;
            if(x[c][d]==0)
            {
                x[c][d]=e;
                s.push(3000*c+d);
            }

            c=min(a+1, n-1);
            d=b;
            if(x[c][d]==0)
            {
                x[c][d]=e;
                s.push(3000*c+d);
            }

            c=a;
            d=max(b-1, a-a);
            if(x[c][d]==0)
            {
                x[c][d]=e;
                s.push(3000*c+d);
            }

            c=a;
            d=min(b+1, m-1);
            if(x[c][d]==0)
            {
                x[c][d]=e;
                s.push(3000*c+d);
            }
        }

        a=x[n-1][m-1];
        b=(a-n-m+2)/2;
        a=a-b;

        w=1e18;
        e=-1;

        for(i=0; i<t; i++)
        {
            scanf("%lld%lld", &c, &d);

            if(c*a+b*d<w)e=1;
            if(c*a+b*d==w)e++;

            w=min(w, c*a+d*b);
        }

        printf("%lld %lld\n", w, e);
    }

    return(0);
}