Submission #705128

# Submission time Handle Problem Language Result Execution time Memory
705128 2023-03-03T12:15:08 Z stevancv Toll (BOI17_toll) C++14
0 / 100
59 ms 33740 KB
// to finish
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e4 + 2;
const int inf = 2e9;
const int mod = 1e9 + 7;
int lift[N][16][5];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k, n, m, q;
    cin >> k >> n >> m >> q;
    for (int i = 0; i < n; i++) {
        for (int l = 0; l < 16; l++) {
            for (int o = 0; o < k; o++) {
                lift[i][l][o] = inf;
            }
        }
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        lift[a][0][b % k] = c;
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int l = 1; l < 16; l++) {
            int nesto = k * (i / k + (1 << l) / 2);
            for (int o = 0; o < k; o++) {
                for (int oo = 0; oo < k; oo++) {
                    smin(lift[i][l][o], lift[i][l - 1][oo] + lift[nesto + oo][l - 1][o]);
                }
            }
        }
    }
    while (q--) {
        int a, b;
        cin >> a >> b;
        int dn = b / k - a / k;
        int cur = a / k;
        vector<int> mn(k, inf);
        mn[a % k] = 0;
        for (int i = 0; i < 16; i++) {
            if ((1 << i) & dn) {
                vector<int> novi(k, inf);
                for (int o = 0; o < k; o++) {
                    for (int oo = 0; oo < k; oo++) {
                        smin(novi[o], mn[oo] + lift[cur * k + oo][i][o]);
                    }
                }
                cur += (1 << i);
                swap(mn, novi);
            }
        }
        if (mn[b % k] == inf) mn[b % k] = -1;
        cout << mn[b % k] << en;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 33100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 33740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 33100 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -