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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k;
    cin >> n;
    cin >> m;
    cin >> k;
    long long sum = 0;
    auto arr = new char[2000][2000];
    char c;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
        {
            cin >> c;
            arr[i][j] = c;
        }

    queue<tuple<int, int, int, int> > q;
    q.emplace(0, 0, 0, 0);
    int minUps, minDowns;

    while (!q.empty())
    {
        auto p = q.front();
        if (get<0>(p) == n - 1 &&  get<1>(p) == m - 1)
        {
            minUps = get<2>(p);
            minDowns = get<3>(p);
            break;
        }

        q.pop();
        arr[get<0>(p)][get<1>(p)] = 'X';

        if (get<0>(p) > 0 && arr[get<0>(p) - 1][get<1>(p)] == '.') {
            arr[get<0>(p) - 1][get<1>(p)] = 'X';
            q.emplace(get<0>(p) - 1, get<1>(p), get<2>(p), get<3>(p) + 1);
        }

        if (get<1>(p) > 0 && arr[get<0>(p)][get<1>(p) - 1] == '.') {
            arr[get<0>(p)][get<1>(p) - 1]= 'X';
            q.emplace(get<0>(p), get<1>(p) - 1, get<2>(p), get<3>(p) + 1);
        }

        if (get<0>(p) < n - 1 && arr[get<0>(p) + 1][get<1>(p)] == '.') {
            arr[get<0>(p) + 1][get<1>(p)] = 'X';
            q.emplace(get<0>(p) + 1, get<1>(p), get<2>(p) + 1, get<3>(p));
        }

        if (get<1>(p) < m - 1 && arr[get<0>(p)][get<1>(p) + 1] == '.') {
            arr[get<0>(p)][get<1>(p) + 1] = 'X';
            q.emplace(get<0>(p), get<1>(p) + 1, get<2>(p) + 1, get<3>(p));
        }
    }

    unsigned long long min = ULLONG_MAX;
    int quantiy = 0;
    unsigned long long a, b;
    for (int i = 0; i < k; ++i)
    {
        cin >> a;
        cin >> b;
        if (a * minUps + b * minDowns == min)
            quantiy++;
        else if (a * minUps + b * minDowns < min)
        {
            quantiy = 1;
            min = a * minUps + b * minDowns;
        }
    }
    cout << min << " " << quantiy << endl;
    return 0;
}