답안 #951877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951877 2024-03-22T21:32:19 Z inkvizytor Toll (BOI17_toll) C++11
100 / 100
366 ms 98428 KB
#include <bits/stdc++.h>
using namespace std;

int k, l;

int logarytm(int a) {
    int w = 0;
    while (a > 0) {
        w++;
        a /= 2;
    }
    return w+1;
}

vector<int> polacz(int a, vector<int> b) {
    vector<int> w (k, -1);
    if (a == -1) {
        return w;
    }
    for (int i = 0; i < k; i++) {
        if (b[i] != -1) {
            w[i] = b[i]+a;
        }
    }
    return w;
}

vector<int> mini(vector<int> a, vector<int> b) {
    vector<int> w (k, 0);
     for (int i = 0; i < k; i++) {
        if (a[i]==-1 || b[i]==-1) {
            w[i] = max(a[i], b[i]);
        }
        else {
            w[i] = min(a[i], b[i]);
        }
     }
     return w;
}

vector<vector<vector<int>>> jp;
vector<vector<vector<int>>> jp2;
vector<int> pot = {1};

int droga (int a, int b) {
    int x = a/k, y = b/k, r = b%k;
    int p = l-1;
    vector<int> odl (5, -1);
    odl[a%k] = 0;
    while (p >= 0) {
        if (x+pot[p]<=y) {
            vector<int> pom (k, -1);
            for (int i = 0; i < k; i++) {
                pom = mini(pom, polacz(odl[i], jp[p][x*k+i]));
            }
            odl = pom;
            x += pot[p];
        }
        p--;
    }
    return odl[r];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 1; i < 20; i++) {
        pot.push_back(pot[i-1]*2);
    }
    int n, m, o;
    cin >> k >> n >> m >> o;
    vector<vector<pair<int, int>>> g (n);
    l = logarytm((n/k)+1);
    jp.resize(l, vector<vector<int>>(n, vector<int>(k, -1)));
    jp2.resize(l, vector<vector<int>>(n, vector<int>(k, -1)));
    for (int i = 0; i < m; i++) {
        int a, b, t;
        cin >> a >> b >> t;
        g[a].push_back(make_pair(b, t));
        jp[0][a][b%k] = t;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
            jp2[0][i][j] = (i/k)*k+k+j;
            if (jp2[0][i][j] >= n) {
                jp2[0][i][j] = n-1;
            }
        }
    }
    for (int i = 1; i < l; i++) {
        for (int j = 0; j < n; j++) {
            for (int x = 0; x < k; x++) {
                jp2[i][j][x] = jp2[i-1][jp2[i-1][j][0]][x];
            }
        }
    }
    for (int i = 1; i < l; i++) {
        for (int j = 0; j < n; j++) {
            for (int x = 0; x < k; x++) {
                jp[i][j] = mini(jp[i][j], polacz(jp[i-1][j][x], jp[i-1][jp2[i-1][j][x]]));
            }
        }
    }
    for (int i = 0; i < o; i++) {
        int a, b;
        cin >> a >> b;
        cout << droga(a, b) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 97516 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1760 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 173 ms 98428 KB Output is correct
9 Correct 188 ms 98296 KB Output is correct
10 Correct 157 ms 97472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 242 ms 92036 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 9 ms 1816 KB Output is correct
8 Correct 12 ms 1628 KB Output is correct
9 Correct 167 ms 98392 KB Output is correct
10 Correct 319 ms 94400 KB Output is correct
11 Correct 221 ms 93628 KB Output is correct
12 Correct 309 ms 93316 KB Output is correct
13 Correct 231 ms 52116 KB Output is correct
14 Correct 169 ms 53652 KB Output is correct
15 Correct 236 ms 50044 KB Output is correct
16 Correct 229 ms 50040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 1628 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 4 ms 1536 KB Output is correct
10 Correct 149 ms 97384 KB Output is correct
11 Correct 202 ms 93496 KB Output is correct
12 Correct 285 ms 94188 KB Output is correct
13 Correct 289 ms 94448 KB Output is correct
14 Correct 291 ms 93768 KB Output is correct
15 Correct 217 ms 49808 KB Output is correct
16 Correct 218 ms 49808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 1628 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 4 ms 1536 KB Output is correct
10 Correct 149 ms 97384 KB Output is correct
11 Correct 202 ms 93496 KB Output is correct
12 Correct 285 ms 94188 KB Output is correct
13 Correct 289 ms 94448 KB Output is correct
14 Correct 291 ms 93768 KB Output is correct
15 Correct 217 ms 49808 KB Output is correct
16 Correct 218 ms 49808 KB Output is correct
17 Correct 218 ms 93588 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 4 ms 1624 KB Output is correct
24 Correct 5 ms 1628 KB Output is correct
25 Correct 10 ms 1628 KB Output is correct
26 Correct 8 ms 1372 KB Output is correct
27 Correct 163 ms 98416 KB Output is correct
28 Correct 292 ms 94152 KB Output is correct
29 Correct 301 ms 94400 KB Output is correct
30 Correct 292 ms 93872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 97516 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 1628 KB Output is correct
6 Correct 3 ms 1760 KB Output is correct
7 Correct 3 ms 1628 KB Output is correct
8 Correct 173 ms 98428 KB Output is correct
9 Correct 188 ms 98296 KB Output is correct
10 Correct 157 ms 97472 KB Output is correct
11 Correct 242 ms 92036 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 0 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 9 ms 1816 KB Output is correct
18 Correct 12 ms 1628 KB Output is correct
19 Correct 167 ms 98392 KB Output is correct
20 Correct 319 ms 94400 KB Output is correct
21 Correct 221 ms 93628 KB Output is correct
22 Correct 309 ms 93316 KB Output is correct
23 Correct 231 ms 52116 KB Output is correct
24 Correct 169 ms 53652 KB Output is correct
25 Correct 236 ms 50044 KB Output is correct
26 Correct 229 ms 50040 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 2 ms 1628 KB Output is correct
33 Correct 3 ms 1628 KB Output is correct
34 Correct 5 ms 1372 KB Output is correct
35 Correct 4 ms 1536 KB Output is correct
36 Correct 149 ms 97384 KB Output is correct
37 Correct 202 ms 93496 KB Output is correct
38 Correct 285 ms 94188 KB Output is correct
39 Correct 289 ms 94448 KB Output is correct
40 Correct 291 ms 93768 KB Output is correct
41 Correct 217 ms 49808 KB Output is correct
42 Correct 218 ms 49808 KB Output is correct
43 Correct 218 ms 93588 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 4 ms 1624 KB Output is correct
50 Correct 5 ms 1628 KB Output is correct
51 Correct 10 ms 1628 KB Output is correct
52 Correct 8 ms 1372 KB Output is correct
53 Correct 163 ms 98416 KB Output is correct
54 Correct 292 ms 94152 KB Output is correct
55 Correct 301 ms 94400 KB Output is correct
56 Correct 292 ms 93872 KB Output is correct
57 Correct 366 ms 89692 KB Output is correct
58 Correct 179 ms 98240 KB Output is correct
59 Correct 249 ms 93724 KB Output is correct