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
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
const vector<pair<int,int> > dirs = {{0,1},{1,0},{-1,0},{0,-1}};


int32_t main(){
    ios::sync_with_stdio(false);
    int n,m,k;
    cin >> n >> m >> k;
    vector<string> tab(n);
    for(int i=0;i<n;i++)
        cin >> tab[i];
    
    queue<pair<int,int> > q;
    vector<vector<int> > dist(n,vector<int>(m,-1));
    q.push({0,0});
    dist[0][0] = 0;
    while(!q.empty()) {
        auto p = q.front();
        q.pop();
        for(auto d : dirs) {
            int a = p.st+d.st, b = p.nd+d.nd;
            if(a >= 0 && b >= 0 && a < n && b < m && tab[a][b] == '.' && dist[a][b] == -1) {
                dist[a][b] = dist[p.st][p.nd]+1;
                q.push({a,b});
            }
        }
    }
    map<long long,int> res;
    while(k--) {
        long long a,b;
        cin >> a >> b;
        res[-b*(n+m-2) + (a+b)*(dist[n-1][m-1]+n+m-2)/2]++;
    }
    cout<<res.begin()->first<<" "<<res.begin()->second<<"\n";
}