답안 #128728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128728 2019-07-11T08:41:50 Z SamAnd Toll (BOI17_toll) C++17
100 / 100
272 ms 22084 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 50010, INF = 1000000009;

int k, n, m, q;
vector<pair<int, int> > a[N];

vector<vector<int> > b[N];

void make(vector<vector<int> >& vv)
{
    vector<int> v;
    for (int i = 0; i < k; ++i)
    {
        vv.push_back(v);
        for (int j = 0; j < k; ++j)
        {
            vv[i].push_back(INF);
        }
    }
}

vector<vector<int> > mer(const vector<vector<int> >& l, const vector<vector<int> >& r)
{
    vector<vector<int> > res;
    make(res);
    for (int x = 0; x < k; ++x)
    {
        for (int y = 0; y < k; ++y)
        {
            for (int z = 0; z < k; ++z)
            {
                res[x][y] = min(res[x][y], l[x][z] + r[z][y]);
            }
        }
    }
    return res;
}

vector<vector<int> > t[N * 4];
void bil(int tl, int tr, int pos)
{
    if (tr < tl)
        return;
    if (tl == tr)
    {
        t[pos] = b[tl];
        return;
    }
    int m = (tl + tr) / 2;
    bil(tl, m, pos * 2);
    bil(m + 1, tr, pos * 2 + 1);
    t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}
vector<vector<int> > qry(int tl, int tr, int l, int r, int pos)
{
    if (tl == l && tr == r)
        return t[pos];
    int m = (tl + tr) / 2;
    if (r <= m)
        return qry(tl, m, l, r, pos * 2);
    if (l > m)
        return qry(m + 1, tr, l, r, pos * 2 + 1);
    return mer(qry(tl, m, l, m, pos * 2), qry(m + 1, tr, m + 1, r, pos * 2 + 1));
}

int main()
{
    scanf("%d%d%d%d", &k, &n, &m, &q);
    while (n % k != 0)
        ++n;
    for (int i = 0; i < m; ++i)
    {
        int x, y, d;
        scanf("%d%d%d", &x, &y, &d);
        a[x].push_back(m_p(y, d));
    }
    for (int i = 0; i < (n / k) - 1; ++i)
    {
        make(b[i]);
        for (int j = 0; j < k; ++j)
        {
            for (int jj = 0; jj < a[i * k + j].size(); ++jj)
            {
                pair<int, int> h = a[i * k + j][jj];
                b[i][j][h.first - (i + 1) * k] = min(b[i][j][h.first - (i + 1) * k], h.second);
            }
        }
    }
    bil(0, n / k - 2, 1);
    while (q--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        int ll = l / k;
        int rr = r / k;
        if (ll >= rr)
        {
            printf("-1\n");
            continue;
        }
        vector<vector<int> > vv = qry(0, n / k - 2, ll, rr - 1, 1);
        if (vv[l % k][r % k] == INF)
            printf("-1\n");
        else
            printf("%d\n", vv[l % k][r % k]);
    }
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:84:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int jj = 0; jj < a[i * k + j].size(); ++jj)
                              ~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &k, &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &x, &y, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 19496 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 10 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 13 ms 7644 KB Output is correct
6 Correct 11 ms 7672 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 101 ms 19448 KB Output is correct
9 Correct 98 ms 19320 KB Output is correct
10 Correct 73 ms 17016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 20088 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7288 KB Output is correct
4 Correct 8 ms 7420 KB Output is correct
5 Correct 8 ms 7348 KB Output is correct
6 Correct 8 ms 7388 KB Output is correct
7 Correct 22 ms 7800 KB Output is correct
8 Correct 30 ms 7672 KB Output is correct
9 Correct 88 ms 19192 KB Output is correct
10 Correct 179 ms 21624 KB Output is correct
11 Correct 143 ms 20124 KB Output is correct
12 Correct 140 ms 19924 KB Output is correct
13 Correct 162 ms 19192 KB Output is correct
14 Correct 95 ms 16084 KB Output is correct
15 Correct 106 ms 16828 KB Output is correct
16 Correct 105 ms 16760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7288 KB Output is correct
5 Correct 8 ms 7292 KB Output is correct
6 Correct 9 ms 7644 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 12 ms 7800 KB Output is correct
9 Correct 11 ms 7672 KB Output is correct
10 Correct 63 ms 19192 KB Output is correct
11 Correct 89 ms 19832 KB Output is correct
12 Correct 121 ms 21496 KB Output is correct
13 Correct 127 ms 22008 KB Output is correct
14 Correct 105 ms 20728 KB Output is correct
15 Correct 76 ms 16760 KB Output is correct
16 Correct 76 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7288 KB Output is correct
5 Correct 8 ms 7292 KB Output is correct
6 Correct 9 ms 7644 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 12 ms 7800 KB Output is correct
9 Correct 11 ms 7672 KB Output is correct
10 Correct 63 ms 19192 KB Output is correct
11 Correct 89 ms 19832 KB Output is correct
12 Correct 121 ms 21496 KB Output is correct
13 Correct 127 ms 22008 KB Output is correct
14 Correct 105 ms 20728 KB Output is correct
15 Correct 76 ms 16760 KB Output is correct
16 Correct 76 ms 16748 KB Output is correct
17 Correct 112 ms 19856 KB Output is correct
18 Correct 8 ms 7416 KB Output is correct
19 Correct 8 ms 7288 KB Output is correct
20 Correct 8 ms 7416 KB Output is correct
21 Correct 8 ms 7416 KB Output is correct
22 Correct 8 ms 7288 KB Output is correct
23 Correct 15 ms 7672 KB Output is correct
24 Correct 19 ms 7672 KB Output is correct
25 Correct 36 ms 7800 KB Output is correct
26 Correct 28 ms 7672 KB Output is correct
27 Correct 73 ms 19192 KB Output is correct
28 Correct 150 ms 21624 KB Output is correct
29 Correct 156 ms 22012 KB Output is correct
30 Correct 134 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 19496 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 10 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 13 ms 7644 KB Output is correct
6 Correct 11 ms 7672 KB Output is correct
7 Correct 11 ms 7672 KB Output is correct
8 Correct 101 ms 19448 KB Output is correct
9 Correct 98 ms 19320 KB Output is correct
10 Correct 73 ms 17016 KB Output is correct
11 Correct 127 ms 20088 KB Output is correct
12 Correct 8 ms 7416 KB Output is correct
13 Correct 8 ms 7288 KB Output is correct
14 Correct 8 ms 7420 KB Output is correct
15 Correct 8 ms 7348 KB Output is correct
16 Correct 8 ms 7388 KB Output is correct
17 Correct 22 ms 7800 KB Output is correct
18 Correct 30 ms 7672 KB Output is correct
19 Correct 88 ms 19192 KB Output is correct
20 Correct 179 ms 21624 KB Output is correct
21 Correct 143 ms 20124 KB Output is correct
22 Correct 140 ms 19924 KB Output is correct
23 Correct 162 ms 19192 KB Output is correct
24 Correct 95 ms 16084 KB Output is correct
25 Correct 106 ms 16828 KB Output is correct
26 Correct 105 ms 16760 KB Output is correct
27 Correct 8 ms 7416 KB Output is correct
28 Correct 8 ms 7416 KB Output is correct
29 Correct 8 ms 7416 KB Output is correct
30 Correct 8 ms 7288 KB Output is correct
31 Correct 8 ms 7292 KB Output is correct
32 Correct 9 ms 7644 KB Output is correct
33 Correct 10 ms 7672 KB Output is correct
34 Correct 12 ms 7800 KB Output is correct
35 Correct 11 ms 7672 KB Output is correct
36 Correct 63 ms 19192 KB Output is correct
37 Correct 89 ms 19832 KB Output is correct
38 Correct 121 ms 21496 KB Output is correct
39 Correct 127 ms 22008 KB Output is correct
40 Correct 105 ms 20728 KB Output is correct
41 Correct 76 ms 16760 KB Output is correct
42 Correct 76 ms 16748 KB Output is correct
43 Correct 112 ms 19856 KB Output is correct
44 Correct 8 ms 7416 KB Output is correct
45 Correct 8 ms 7288 KB Output is correct
46 Correct 8 ms 7416 KB Output is correct
47 Correct 8 ms 7416 KB Output is correct
48 Correct 8 ms 7288 KB Output is correct
49 Correct 15 ms 7672 KB Output is correct
50 Correct 19 ms 7672 KB Output is correct
51 Correct 36 ms 7800 KB Output is correct
52 Correct 28 ms 7672 KB Output is correct
53 Correct 73 ms 19192 KB Output is correct
54 Correct 150 ms 21624 KB Output is correct
55 Correct 156 ms 22012 KB Output is correct
56 Correct 134 ms 20828 KB Output is correct
57 Correct 272 ms 22084 KB Output is correct
58 Correct 103 ms 19320 KB Output is correct
59 Correct 163 ms 20132 KB Output is correct