Submission #753723

#TimeUsernameProblemLanguageResultExecution timeMemory
753723aminToll (BOI17_toll)C++14
100 / 100
140 ms35516 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int p[17][100000][5],mi[17][100000][5]; int k; int get(int x,int y) { int di=y/k-x/k; if(di<=0) return -1; int o=0; int j=1; vector<int>b(5),c(5),d(5),bb(5); for(int i=0;i<5;i++) { b[i]=-1; c[i]=-1; d[i]=1000000000; } b[x%k]=x; d[x%k]=0; while(o<17) { if((di&j)==j) { c=d; d[0]=1e9; d[1]=d[0]; d[2]=d[0]; d[3]=d[0]; d[4]=d[0]; for(int h=0;h<5;h++) bb[h]=-1; for(int i=0;i<k;i++) { for(int u=0;u<k;u++) { if(b[u]==-1||p[o][b[u]][i]==-1) continue; //cout<<"whatever"<<endl; bb[i]=p[o][b[u]][i]; d[i]=min(d[i],c[u]+mi[o][b[u]][i]); } } b=bb; c=d; /*for(int i=0;i<k;i++) { cout<<b[i]<<' '; } cout<<endl;*/ } j*=2; o++; } return c[y%k]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("balancing.in","r",stdin); // freopen("balancing.out","w",stdout); int n,m,o; cin>>k>>n>>m>>o; vector<int>v[n+1]; for(int i=0;i<17;i++) { for(int y=0;y<n;y++) { for(int h=0;h<k;h++) { p[i][y][h]=-1; } } } for(int i=0;i<m;i++) { int x,y,t; cin>>x>>y>>t; v[x].push_back(y); p[0][x][y%k]=y; mi[0][x][y%k]=t; } for(int i=0;i<17;i++) { for(int y=0;y<n;y++) { for(int u=0;u<k;u++) { for(int z=0;z<k;z++) { if(i) { if(p[i-1][y][z]==-1||p[i-1][p[i-1][y][z]][u]==-1) continue; p[i][y][u]=p[i-1][p[i-1][y][z]][u]; if(mi[i][y][u]==0) mi[i][y][u]=1e9; mi[i][y][u]=min(mi[i][y][u],mi[i-1][y][z]+mi[i-1][p[i-1][y][z]][u]); } } /* if(i<5) { cout<<p[i][y][u]<<' '; }*/ } // if(i<5) // cout<<endl; } //if(i<5) // cout<<endl; } while(o--) { int x,y; cin>>x>>y; int ans=get(x,y); if(ans>=1000000000) cout<<-1<<endl; else cout<<ans<<endl; } }

Compilation message (stderr)

toll.cpp: In function 'int get(int, int)':
toll.cpp:43:18: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   43 |                  if(b[u]==-1||p[o][b[u]][i]==-1)
      |                  ^~
toll.cpp:46:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   46 |                     bb[i]=p[o][b[u]][i];
      |                     ^~
#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...