Submission #678750

#TimeUsernameProblemLanguageResultExecution timeMemory
678750alexddToll (BOI17_toll)C++17
46 / 100
3104 ms396248 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...