Submission #678755

# Submission time Handle Problem Language Result Execution time Memory
678755 2023-01-06T13:20:00 Z alexdd Toll (BOI17_toll) C++17
100 / 100
1848 ms 489496 KB
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int dim = 2500;
const int INF = 1000000007;
int n,q,k,m;
vector<pair<int,int>> con[50001];
int dist[50001][dim];
int query(int st, int dr)
{
    if(dr<st)
        return INF;
    if(dr-st<dim)
        return dist[dr][(dr-st)];
    int mij=(st+dr)/2;
    int mnm=INF;
    for(int i=0;i<2*k-1;i++)
        mnm=min(mnm,query(st,mij+i)+query(mij+i,dr));
    return mnm;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    cin>>k>>n>>m>>q;
    int a,b,c;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        con[b].push_back({a,c});
    }
    for(int i=0;i<n;i++)
    {
        ///calc dist[i][]
        dist[i][0]=0;
        for(int j=1;j<=min(i,dim-1);j++)
        {
            dist[i][j] = INF;
            for(auto adj:con[i])
                if(adj.first >= i-j)
                    dist[i][j]=min(dist[i][j], dist[adj.first][(adj.first - i + j)] + adj.second);
        }
    }
    int rez;
    for(int i=0;i<q;i++)
    {
        cin>>a>>b;
        rez=query(a,b);
        if(rez>=INF)
            rez=-1;
        cout<<rez<<"\n";
    }
    return 0;
}
/**



*/

# Verdict Execution time Memory Grader output
1 Correct 504 ms 488012 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 5 ms 7380 KB Output is correct
8 Correct 510 ms 488052 KB Output is correct
9 Correct 513 ms 488100 KB Output is correct
10 Correct 245 ms 486476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 785 ms 487992 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 7 ms 7508 KB Output is correct
8 Correct 7 ms 7508 KB Output is correct
9 Correct 508 ms 488040 KB Output is correct
10 Correct 1468 ms 489164 KB Output is correct
11 Correct 850 ms 488268 KB Output is correct
12 Correct 1442 ms 488056 KB Output is correct
13 Correct 1091 ms 293544 KB Output is correct
14 Correct 634 ms 292556 KB Output is correct
15 Correct 787 ms 292040 KB Output is correct
16 Correct 752 ms 292116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 7 ms 7380 KB Output is correct
8 Correct 11 ms 7508 KB Output is correct
9 Correct 8 ms 7508 KB Output is correct
10 Correct 514 ms 487944 KB Output is correct
11 Correct 768 ms 487920 KB Output is correct
12 Correct 1044 ms 488872 KB Output is correct
13 Correct 1022 ms 489096 KB Output is correct
14 Correct 905 ms 488412 KB Output is correct
15 Correct 548 ms 292008 KB Output is correct
16 Correct 601 ms 291944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 7 ms 7380 KB Output is correct
8 Correct 11 ms 7508 KB Output is correct
9 Correct 8 ms 7508 KB Output is correct
10 Correct 514 ms 487944 KB Output is correct
11 Correct 768 ms 487920 KB Output is correct
12 Correct 1044 ms 488872 KB Output is correct
13 Correct 1022 ms 489096 KB Output is correct
14 Correct 905 ms 488412 KB Output is correct
15 Correct 548 ms 292008 KB Output is correct
16 Correct 601 ms 291944 KB Output is correct
17 Correct 797 ms 487932 KB Output is correct
18 Correct 1 ms 1440 KB Output is correct
19 Correct 1 ms 1492 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 1492 KB Output is correct
22 Correct 1 ms 1492 KB Output is correct
23 Correct 6 ms 7380 KB Output is correct
24 Correct 6 ms 7508 KB Output is correct
25 Correct 11 ms 7476 KB Output is correct
26 Correct 9 ms 7448 KB Output is correct
27 Correct 575 ms 487960 KB Output is correct
28 Correct 1040 ms 488920 KB Output is correct
29 Correct 1063 ms 489152 KB Output is correct
30 Correct 859 ms 488516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 488012 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 5 ms 7380 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 5 ms 7380 KB Output is correct
8 Correct 510 ms 488052 KB Output is correct
9 Correct 513 ms 488100 KB Output is correct
10 Correct 245 ms 486476 KB Output is correct
11 Correct 785 ms 487992 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1492 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 7 ms 7508 KB Output is correct
18 Correct 7 ms 7508 KB Output is correct
19 Correct 508 ms 488040 KB Output is correct
20 Correct 1468 ms 489164 KB Output is correct
21 Correct 850 ms 488268 KB Output is correct
22 Correct 1442 ms 488056 KB Output is correct
23 Correct 1091 ms 293544 KB Output is correct
24 Correct 634 ms 292556 KB Output is correct
25 Correct 787 ms 292040 KB Output is correct
26 Correct 752 ms 292116 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 1 ms 1492 KB Output is correct
29 Correct 1 ms 1492 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 5 ms 7380 KB Output is correct
33 Correct 7 ms 7380 KB Output is correct
34 Correct 11 ms 7508 KB Output is correct
35 Correct 8 ms 7508 KB Output is correct
36 Correct 514 ms 487944 KB Output is correct
37 Correct 768 ms 487920 KB Output is correct
38 Correct 1044 ms 488872 KB Output is correct
39 Correct 1022 ms 489096 KB Output is correct
40 Correct 905 ms 488412 KB Output is correct
41 Correct 548 ms 292008 KB Output is correct
42 Correct 601 ms 291944 KB Output is correct
43 Correct 797 ms 487932 KB Output is correct
44 Correct 1 ms 1440 KB Output is correct
45 Correct 1 ms 1492 KB Output is correct
46 Correct 2 ms 1492 KB Output is correct
47 Correct 1 ms 1492 KB Output is correct
48 Correct 1 ms 1492 KB Output is correct
49 Correct 6 ms 7380 KB Output is correct
50 Correct 6 ms 7508 KB Output is correct
51 Correct 11 ms 7476 KB Output is correct
52 Correct 9 ms 7448 KB Output is correct
53 Correct 575 ms 487960 KB Output is correct
54 Correct 1040 ms 488920 KB Output is correct
55 Correct 1063 ms 489152 KB Output is correct
56 Correct 859 ms 488516 KB Output is correct
57 Correct 1848 ms 489496 KB Output is correct
58 Correct 513 ms 488068 KB Output is correct
59 Correct 784 ms 488080 KB Output is correct