Submission #938637

# Submission time Handle Problem Language Result Execution time Memory
938637 2024-03-05T11:35:22 Z faruk Toll (BOI17_toll) C++17
39 / 100
3000 ms 8424 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;

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

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

    while (q--) {
        int f, t;
        cin >> f >> t;
        int SF = f / k, ST = t / k;
        vector<ll> ans(k, 1e18);
        ans[f % k] = 0;
        for (int i = SF; i < ST; i++) {
            vector<ll> neww(k, 1e18);
            for (int j = 0; j < k; j++)
                for (auto &[to, w] : graph[i * k + j])
                    neww[to] = min(neww[to], ans[j] + w);
            ans = neww;
        }

        if (ans[t % k] == 1e18)
            cout << "-1\n";
        else
            cout << ans[t % k] << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3026 ms 3412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3036 ms 4408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 57 ms 3948 KB Output is correct
11 Correct 51 ms 5720 KB Output is correct
12 Correct 64 ms 7504 KB Output is correct
13 Correct 59 ms 8276 KB Output is correct
14 Correct 54 ms 6492 KB Output is correct
15 Correct 32 ms 4296 KB Output is correct
16 Correct 31 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 560 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 57 ms 3948 KB Output is correct
11 Correct 51 ms 5720 KB Output is correct
12 Correct 64 ms 7504 KB Output is correct
13 Correct 59 ms 8276 KB Output is correct
14 Correct 54 ms 6492 KB Output is correct
15 Correct 32 ms 4296 KB Output is correct
16 Correct 31 ms 4188 KB Output is correct
17 Correct 787 ms 5708 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 17 ms 344 KB Output is correct
24 Correct 13 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 14 ms 604 KB Output is correct
27 Correct 1224 ms 4024 KB Output is correct
28 Correct 718 ms 7764 KB Output is correct
29 Correct 776 ms 8424 KB Output is correct
30 Correct 781 ms 6872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3026 ms 3412 KB Time limit exceeded
2 Halted 0 ms 0 KB -