Submission #540807

# Submission time Handle Problem Language Result Execution time Memory
540807 2022-03-21T19:42:43 Z Olympia Toll (BOI17_toll) C++17
0 / 100
2 ms 1360 KB
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <type_traits>
#include <string>
#include <queue>
#define ll long long
#include <map>

using namespace std;
int64_t dp[100][32][5][5];
int K, N, M, O;
vector<vector<int64_t>> f (int in1, int in2) {
    vector<vector<int64_t>> cur(K);
    for (int i = 0; i < K; i++) {
        cur[i].assign(K, INT_MAX);
        cur[i][i] = 0;
    }
    int dif = abs(in1 - in2);
    while (dif > 0) {
        vector<vector<int64_t>> new_cur = cur;
        for (int i = 0; i < K; i++) {
            new_cur[i].assign(K, INT_MAX);
        }
        int lg2 = log2(dif);
        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                for (int k = 0; k < K; k++) {
                     new_cur[i][j] = min(new_cur[i][j], cur[i][k] + dp[in1][lg2][k][j]);
                }
            }
        }
        dif -= (1 << lg2);
        in1 += (1 << lg2);
        cur = new_cur;
    }
    return cur;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> K >> N >> M >> O;
    N++;
    while (N % K != K - 1) {
        N++;
    }
    //dp[i][j][x][y] -> K * i + x, K * (i + 2^j) + y
    for (int j = 0; j < 32; j++) {
        for (int i = 0; i < N/K; i++) {
            for (int x = 0; x < K; x++) {
                for (int y = 0; y < K; y++) {
                    dp[i][j][x][y] = INT_MAX;
                }
            }
        }
    }
    vector<vector<pair<int,int>>> adj(N);
    while (M--) {
        int a, b, w;
        cin >> a >> b >> w;
        adj[a].emplace_back(b, w);
        dp[a/K][0][a % K][b % K] = w;
    }
    for (int j = 1; j < 32; j++) {
        for (int i = 0; i < N/K; i++) {
            for (int x = 0; x < K; x++) {
                for (int y = 0; y < K; y++) {
                    for (int z = 0; z < K; z++) {
                        if (i + (1 << (j - 1)) < N/K)
                        dp[i][j][x][y] = min(dp[i][j][x][y], dp[i][j - 1][x][z] + dp[i + (1 << (j - 1))][j - 1][z][y]);
                    }
                    if (dp[i][j][x][y] != INT_MAX) {
                        cout << j << " " << K * i + x << " " << K * (i + (1 << j)) + y << " " << dp[i][j][x][y] << '\n';
                    }
                }
            }
        }
    }
    while (O--) {
        int a, b;
        cin >> a >> b;
        if (a/K == b/K) {
            cout << "-1\n";
            continue;
        }
        vector<vector<int64_t>> vec = f(a/K, b/K);
        if (vec[a % K][b % K] == INT_MAX) {
            cout << "-1\n";
            continue;
        }
        cout << vec[a % K][b % K] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1236 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1236 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -