답안 #547389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547389 2022-04-10T15:20:38 Z Jomnoi Toll (BOI17_toll) C++17
0 / 100
34 ms 40344 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int MAX_N = 1e4 + 10;
const int MAX_B = 20;
const int MAX_K = 5;
const int INF = 1e9 + 7;

int N, K;
int dist[MAX_N][MAX_B][MAX_K][MAX_K];
int now[MAX_K][MAX_K], prv[MAX_K][MAX_K];

void init() {
    for(int i = 0; i < MAX_N; i++) {
        for(int j = 0; j < MAX_B; j++) {
            for(int k = 0; k < MAX_K; k++) {
                for(int l = 0; l < MAX_K; l++) {
                    dist[i][j][k][l] = INF;
                }
            }
        }
    }
}

void FloydWarshall(int c[MAX_K][MAX_K], int a[MAX_K][MAX_K], int b[MAX_K][MAX_K]) {
    for(int k = 0; k < K; k++) {
        for(int i = 0; i < K; i++) {
            for(int j = 0; j < K; j++) {
                c[i][j] = min(c[i][j], a[i][k] + b[k][j]);
            }
        }
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    init();

    int M, O;
    cin >> K >> N >> M >> O;

    while(M--) {
        int a, b, t;
        cin >> a >> b >> t;
        dist[a / K][0][a % K][b % K] = min(dist[a / K][0][a % K][b % K], t);
    }

    for(int j = 1; (1<<j) <= N / K; j++) {
        for(int i = 0; i + (1<<j) - 1 <= N / K; i++) {
            FloydWarshall(dist[i][j], dist[i][j - 1], dist[i + (1<<(j - 1))][j - 1]);
        }
    }

    while(O--) {
        int a, b;
        cin >> a >> b;
        if(a / K == b / K) {
            cout << "-1\n";
            continue;
        }

        for(int i = 0; i < K; i++) {
            for(int j = 0; j < K; j++) {
                prv[i][j] = INF;
                if(i == j) {
                    prv[i][j] = 0;
                }
            }
        }
        int s = a / K, t = b / K;
        for(int j = MAX_B - 1; j >= 0; j--) {
            if(s + (1<<j) > t) {
                continue;
            }

            for(int k = 0; k < K; k++) {
                for(int l = 0; l < K; l++) {
                    now[k][l] = prv[k][l];
                    prv[k][l] = INF;
                }
            }
            FloydWarshall(prv, now, dist[s][j]);
            s += (1<<j);
        }

        if(prv[a % K][b % K] == INF) {
            cout << "-1\n";
        }
        else {
            cout << prv[a % K][b % K] << '\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 40268 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 40140 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19908 KB Output is correct
2 Correct 10 ms 19844 KB Output is correct
3 Correct 11 ms 19796 KB Output is correct
4 Correct 11 ms 19900 KB Output is correct
5 Correct 10 ms 19796 KB Output is correct
6 Correct 10 ms 19920 KB Output is correct
7 Correct 13 ms 19928 KB Output is correct
8 Correct 13 ms 19924 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Runtime error 27 ms 40344 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19908 KB Output is correct
2 Correct 10 ms 19844 KB Output is correct
3 Correct 11 ms 19796 KB Output is correct
4 Correct 11 ms 19900 KB Output is correct
5 Correct 10 ms 19796 KB Output is correct
6 Correct 10 ms 19920 KB Output is correct
7 Correct 13 ms 19928 KB Output is correct
8 Correct 13 ms 19924 KB Output is correct
9 Correct 11 ms 19924 KB Output is correct
10 Runtime error 27 ms 40344 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 40268 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -