Submission #938690

# Submission time Handle Problem Language Result Execution time Memory
938690 2024-03-05T12:37:55 Z faruk Toll (BOI17_toll) C++17
0 / 100
206 ms 85668 KB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<vector<ll> > vvi;

vector<vector<pii> > graph;
int k;
vvi combine(vvi beg, int bn, vvi endd) {
    vvi ans(k, vector<ll>(k, 1e18));
    for (int i = 0; i < k; i++)
        for (auto &[to, w] : graph[bn * k + i])
            for (int j = 0; j < k; j++)
                ans[i][j] = min(ans[i][j], beg[i][i] + w + endd[to][j]);
    return ans;
}

const int lg = 18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, q;
    cin >> k >> n >> m >> q;
    graph = vector<vector<pii> >(n + 2 * k);
    for (int i = 0; i < m; i++) {
        int f, t, p;
        cin >>f >> t >> p;
        graph[f].push_back(pii(t % k, p));
    }

    vector<vector<vvi> > lift(lg, vector<vvi> (n / k + 1, vvi(k, vector<ll>(k, 1e18))));
    int num_lay = n / k + 1;
    for (int i = 0; i < num_lay; i++)
        for (int j = 0; j < k; j++)
            lift[0][i][j][j] = 0;
    for (int bit = 1; bit < lg; bit++)
        for (int i = num_lay - (1 << (bit - 1)) - 1; i >= 0; i--) 
            lift[bit][i] = combine(lift[bit - 1][i], i, lift[bit - 1][i + (1 << (bit - 1))]);


    while (q--) {
        int f, t;
        cin >> f >> t;
        int SF = f / k, ST = t / k;
        vvi ans(k, vector<ll>(k, 1e18));
        ans[f % k][f % k] = 0;
        int diff = ST - SF;
        for (int i = 0; i < lg; i++) {
            if (((1 << i) & diff) != 0) {
                ans = combine(ans, SF, lift[i][SF + 1]);
                SF += (1 << i);
            }
        }

        if (ans[f % k][t % k] == 1e18)
            cout << "-1\n";
        else
            cout << ans[f % k][t % k] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 85668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 189 ms 75600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 206 ms 85668 KB Output isn't correct
2 Halted 0 ms 0 KB -