Submission #678754

# Submission time Handle Problem Language Result Execution time Memory
678754 2023-01-06T13:19:08 Z alexdd Toll (BOI17_toll) C++17
100 / 100
2446 ms 397312 KB
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int dim = 2000;
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 413 ms 392560 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 1536 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 415 ms 392560 KB Output is correct
9 Correct 404 ms 392440 KB Output is correct
10 Correct 203 ms 391008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 695 ms 392596 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 6 ms 7500 KB Output is correct
8 Correct 8 ms 7508 KB Output is correct
9 Correct 426 ms 392552 KB Output is correct
10 Correct 1610 ms 393660 KB Output is correct
11 Correct 715 ms 394244 KB Output is correct
12 Correct 1329 ms 393836 KB Output is correct
13 Correct 996 ms 239472 KB Output is correct
14 Correct 517 ms 237568 KB Output is correct
15 Correct 704 ms 236860 KB Output is correct
16 Correct 702 ms 237004 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 6 ms 7380 KB Output is correct
8 Correct 9 ms 7508 KB Output is correct
9 Correct 8 ms 7388 KB Output is correct
10 Correct 427 ms 392488 KB Output is correct
11 Correct 583 ms 392456 KB Output is correct
12 Correct 746 ms 393416 KB Output is correct
13 Correct 823 ms 393740 KB Output is correct
14 Correct 661 ms 393088 KB Output is correct
15 Correct 424 ms 235716 KB Output is correct
16 Correct 418 ms 235784 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 6 ms 7380 KB Output is correct
8 Correct 9 ms 7508 KB Output is correct
9 Correct 8 ms 7388 KB Output is correct
10 Correct 427 ms 392488 KB Output is correct
11 Correct 583 ms 392456 KB Output is correct
12 Correct 746 ms 393416 KB Output is correct
13 Correct 823 ms 393740 KB Output is correct
14 Correct 661 ms 393088 KB Output is correct
15 Correct 424 ms 235716 KB Output is correct
16 Correct 418 ms 235784 KB Output is correct
17 Correct 623 ms 392556 KB Output is correct
18 Correct 1 ms 1492 KB Output is correct
19 Correct 2 ms 1492 KB Output is correct
20 Correct 1 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 7356 KB Output is correct
24 Correct 7 ms 7380 KB Output is correct
25 Correct 11 ms 7508 KB Output is correct
26 Correct 11 ms 7452 KB Output is correct
27 Correct 428 ms 392536 KB Output is correct
28 Correct 888 ms 393584 KB Output is correct
29 Correct 946 ms 393840 KB Output is correct
30 Correct 760 ms 393068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 392560 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 1536 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 415 ms 392560 KB Output is correct
9 Correct 404 ms 392440 KB Output is correct
10 Correct 203 ms 391008 KB Output is correct
11 Correct 695 ms 392596 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 6 ms 7500 KB Output is correct
18 Correct 8 ms 7508 KB Output is correct
19 Correct 426 ms 392552 KB Output is correct
20 Correct 1610 ms 393660 KB Output is correct
21 Correct 715 ms 394244 KB Output is correct
22 Correct 1329 ms 393836 KB Output is correct
23 Correct 996 ms 239472 KB Output is correct
24 Correct 517 ms 237568 KB Output is correct
25 Correct 704 ms 236860 KB Output is correct
26 Correct 702 ms 237004 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 6 ms 7380 KB Output is correct
34 Correct 9 ms 7508 KB Output is correct
35 Correct 8 ms 7388 KB Output is correct
36 Correct 427 ms 392488 KB Output is correct
37 Correct 583 ms 392456 KB Output is correct
38 Correct 746 ms 393416 KB Output is correct
39 Correct 823 ms 393740 KB Output is correct
40 Correct 661 ms 393088 KB Output is correct
41 Correct 424 ms 235716 KB Output is correct
42 Correct 418 ms 235784 KB Output is correct
43 Correct 623 ms 392556 KB Output is correct
44 Correct 1 ms 1492 KB Output is correct
45 Correct 2 ms 1492 KB Output is correct
46 Correct 1 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 7356 KB Output is correct
50 Correct 7 ms 7380 KB Output is correct
51 Correct 11 ms 7508 KB Output is correct
52 Correct 11 ms 7452 KB Output is correct
53 Correct 428 ms 392536 KB Output is correct
54 Correct 888 ms 393584 KB Output is correct
55 Correct 946 ms 393840 KB Output is correct
56 Correct 760 ms 393068 KB Output is correct
57 Correct 2446 ms 397312 KB Output is correct
58 Correct 416 ms 393448 KB Output is correct
59 Correct 663 ms 394272 KB Output is correct