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
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    int n,m,k;
    cin >> n>>m>>k;
    int e[n][m];
    for (int i=0; i<n;i++){
        for (int j=0; j<m;j++){
            char tmp;
            cin >> tmp;
            e[i][j]=(int)(tmp=='X')*(-1);
        }
    }
    vector <pair<int,int> > kk;
    for (int i=0;i<k;i++){
        int k1,k2;
        cin >> k1 >> k2;
        kk.push_back(make_pair(k1,k2));
    }
    queue <pair<int,int> > q;
    q.push(make_pair(n-1,m-1));
    int tmpx[4]={-1,0,1,0};
    int tmpy[4]={0,-1,0,1};
    while (!q.empty()){
        auto tmp = q.front();
        //cout << tmp.first << " "<<tmp.second<<endl;
        q.pop();
        for (int i=0; i<4;i++){
            if (tmp.first+tmpx[i]>=0 && tmp.first+tmpx[i]<n && tmp.second+tmpy[i]>=0 && tmp.second+tmpy[i]<m){
                if (e[tmp.first+tmpx[i]][tmp.second+tmpy[i]]==0){
                    e[tmp.first+tmpx[i]][tmp.second+tmpy[i]]=i+1;
                    q.push(make_pair(tmp.first+tmpx[i],tmp.second+tmpy[i]));
                }
            }
        }
    }
    pair<int,int> tmp=make_pair(0,0);
    vector <bool> cos;
    int l1=0;
    int l2=0;
    while(tmp!=make_pair(n-1,m-1)){
        int tmp2=e[tmp.first][tmp.second];
        tmp.first-=tmpx[tmp2-1];
        tmp.second-=tmpy[tmp2-1];
        //cout << tmp.first<<" "<<tmp.second<<" "<<tmp2<<endl;
        if (tmp2-1<2){
            l1++;
        }else{
            l2++;
        }
    }
    long long mini=(1<<20);
    mini*=(1<<20);
    mini*=(1<<20);
    int wynik=0;
    for (int i=0; i<kk.size();i++){
        long long tmp=(long long)l1*(long long)kk[i].first+(long long)l2*(long long)kk[i].second;
        if (mini==tmp){
            wynik++;
        }
        if (mini>tmp){
            mini=tmp;
            wynik=1;
        }
    }
    cout << mini<<" "<<wynik<<endl;
}