답안 #860496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860496 2023-10-13T06:53:50 Z The_Samurai Toll (BOI17_toll) C++17
0 / 100
3000 ms 7512 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e9;

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, m, k, q;
    cin >> k >> n >> m >> q;
    vector queries(n, vector<pair<int, int>>());
    vector<int> ans(q);
    vector<vector<pair<int, int>>> out(n);
    while (m--) {
        int u, v, t;
        cin >> u >> v >> t;
        out[u].emplace_back(v, t);
    }
    for (int i = 0; i < q; i++) {
        int u, v;
        cin >> u >> v;
        queries[u].emplace_back(v, i);
    }
    vector dist(k, vector(n, inf));
    for (int i = n - 1; i / k == (n - 1) / k; i--) dist[i % k][i] = 0;
    for (int i = (n - 1) / k - 1; i >= 0; i--) {
        int left = k * i, right = k * (i + 1) - 1;
        vector new_dist(k, vector(n, inf));
        for (int u = left; u <= right; u++) {
            new_dist[u % k][u] = 0;
            for (auto [v, t]: out[u]) {
                for (int j = 0; j < n; j++) {
                    new_dist[u % k][j] = min(new_dist[u % k][j], dist[v % k][j] + t);
                }
            }
            for (auto [v, j]: queries[u]) {
                ans[j] = new_dist[u % k][v];
            }
        }
        dist = new_dist;
    }
    for (int i = 0; i < q; i++) cout << (ans[i] == inf ? -1 : ans[i]) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3054 ms 6040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3049 ms 7512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3054 ms 6040 KB Time limit exceeded
2 Halted 0 ms 0 KB -