Submission #979183

# Submission time Handle Problem Language Result Execution time Memory
979183 2024-05-10T10:55:18 Z chautanphat Toll (BOI17_toll) C++14
49 / 100
3000 ms 25624 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 5e4;
 
struct query
{
    int a, b, id, ans;
} queries[N];
int k, n, m, o, cost[N][5][5];
 
void dnc(int l, int r, int level = 0)
{
    if (l == r) return;
    int mid = (l+r)/2, L[n/k+1][k][k], R[n/k+1][k][k];
    for (int i = l; i <= r; i++)
        for (int a = 0; a < k; a++)
            for (int b = 0; b < k; b++)
                L[i][a][b] = R[i][a][b] = 1e9;
    for (int a = 0; a < k; a++)
        L[mid][a][a] = 0;
    for (int i = mid-1; i >= l; i--)
        for (int a = 0; a < k; a++)
            for (int b = 0; b < k; b++)
                for (int c = 0; c < k; c++)
                    L[i][a][c] = min(L[i][a][c], L[i+1][b][c]+cost[i][a][b]);
    for (int a = 0; a < k; a++)
        for (int b = 0; b < k; b++)
            R[mid+1][a][b] = cost[mid][a][b];
    for (int i = mid+2; i <= r; i++)
        for (int a = 0; a < k; a++)
            for (int b = 0; b < k; b++)
                for (int c = 0; c < k; c++)
                    R[i][c][a] = min(R[i][c][a], R[i-1][c][b]+cost[i-1][b][a]);
    for (int i = 0; i < o; i++)
    {
        int a = queries[i].a, b = queries[i].b;
        if (l <= a/k && a/k <= mid && mid+1 <= b/k && b/k <= r)
            for (int j = 0; j < k; j++)
                queries[i].ans = min(queries[i].ans, L[a/k][a%k][j]+R[b/k][j][b%k]);
    }
 
    dnc(l, mid, level+1);
    dnc(mid+1, r, level+1);
}
 
int main()
{    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> k >> n >> m >> o;
 
    for (int i = 0; i < n; i++)
        for (int a = 0; a < k; a++)
            for (int b = 0; b < k; b++)
                cost[i][a][b] = 1e9;
 
    for (int i = 0; i < m; i++)
    {
        int a, b, t;
        cin >> a >> b >> t;
        cost[a/k][a%k][b%k] = t;
    }
 
    for (int i = 0; i < o; i++)
        cin >> queries[i].a >> queries[i].b, queries[i].id = i, queries[i].ans = 1e9;
 
    dnc(0, n/k);
 
    for (int i = 0; i < o; i++)
        cout << (queries[i].ans == 1e9 ? -1 : queries[i].ans) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 12892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1178 ms 18832 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 46 ms 860 KB Output is correct
8 Correct 25 ms 1104 KB Output is correct
9 Correct 2234 ms 12632 KB Output is correct
10 Correct 838 ms 25432 KB Output is correct
11 Correct 1178 ms 18920 KB Output is correct
12 Correct 824 ms 24388 KB Output is correct
13 Correct 152 ms 22432 KB Output is correct
14 Correct 187 ms 16212 KB Output is correct
15 Correct 137 ms 21220 KB Output is correct
16 Correct 138 ms 21260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 732 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 121 ms 12380 KB Output is correct
11 Correct 122 ms 18520 KB Output is correct
12 Correct 123 ms 24912 KB Output is correct
13 Correct 124 ms 25368 KB Output is correct
14 Correct 126 ms 24756 KB Output is correct
15 Correct 63 ms 21084 KB Output is correct
16 Correct 64 ms 21180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 732 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 860 KB Output is correct
10 Correct 121 ms 12380 KB Output is correct
11 Correct 122 ms 18520 KB Output is correct
12 Correct 123 ms 24912 KB Output is correct
13 Correct 124 ms 25368 KB Output is correct
14 Correct 126 ms 24756 KB Output is correct
15 Correct 63 ms 21084 KB Output is correct
16 Correct 64 ms 21180 KB Output is correct
17 Correct 565 ms 18700 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 0 ms 464 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 18 ms 600 KB Output is correct
24 Correct 10 ms 604 KB Output is correct
25 Correct 6 ms 860 KB Output is correct
26 Correct 6 ms 860 KB Output is correct
27 Correct 1028 ms 12480 KB Output is correct
28 Correct 425 ms 25420 KB Output is correct
29 Correct 429 ms 25624 KB Output is correct
30 Correct 422 ms 24840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 12892 KB Time limit exceeded
2 Halted 0 ms 0 KB -