Submission #500846

#TimeUsernameProblemLanguageResultExecution timeMemory
500846mars4Toll (BOI17_toll)C++17
100 / 100
311 ms169924 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define ll int64_t #define ld long double #define nl cout<<"\n" #define all(v) v.begin(),v.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i) #define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i) #define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mod 1'000'000'007 #define mod2 998'244'353 #define inf 1'000'000'000'000'007 #define pi 3.14159265358979323846 template<class key,class cmp=std::less<key>> using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>; template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";} template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";} template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";} template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";} void dbg_out() {cerr<<"]\n";} template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);} #ifdef LOCAL #define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //---------------------------------mars4--------------------------------- ll dp[50000][17][5][5]; void combine(ll a[5][5],ll b[5][5],ll c[5][5]) { forn(i,0,5) { forn(j,0,5) { forn(k,0,5) { a[i][k]=min(a[i][k],b[i][j]+c[j][k]); } } } } int main() { fastio(); ll z,n,m,t,k,i,j,l,d,h,r; mset(dp,0x3f); ll q; cin>>k>>n>>m>>q; forn(i,0,m) { cin>>l>>r>>d; dp[l/k][0][l%k][r%k]=d; } for(int j=1;j<17;j++) { for(int i=0;i+(1ll<<j)<(n+k-1)/k;i++) { combine(dp[i][j],dp[i][j-1],dp[i+(1ll<<(j-1))][j-1]); } } forn(i,0,q) { cin>>l>>r; ll cl=l,cr=r; l/=k; r/=k; ll res[5][5]; mset(res,0x0f); forn(j,0,5) { res[j][j]=0; } for(ll j=16;j>=0;j--) { if(l+(1ll<<j)<=r) { ll nres[5][5]; mset(nres,0x3f); combine(nres,res,dp[l][j]); forn(i1,0,5) { forn(j1,0,5) { res[i1][j1]=nres[i1][j1]; } } l+=(1ll<<j); } } if(res[cl%k][cr%k]>=inf) { cout<<"-1\n"; } else { cout<<res[cl%k][cr%k]<<"\n"; } } cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n"; return 0; }

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:63:5: warning: unused variable 'z' [-Wunused-variable]
   63 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
toll.cpp:63:11: warning: unused variable 't' [-Wunused-variable]
   63 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
toll.cpp:63:15: warning: unused variable 'i' [-Wunused-variable]
   63 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
toll.cpp:63:17: warning: unused variable 'j' [-Wunused-variable]
   63 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                 ^
toll.cpp:63:23: warning: unused variable 'h' [-Wunused-variable]
   63 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                       ^
#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...