Submission #245149

#TimeUsernameProblemLanguageResultExecution timeMemory
245149m3r8Toll (BOI17_toll)C++14
100 / 100
499 ms34808 KiB
#include <stdio.h> #define N 100100 int bst[N][17][5]; int nm[N][17][5]; int adj[N][5]; int k,n; int bb[5]; int nxt[5]; int solve(int akt, int en){ //printf("%d %d %d\n",akt,en,bb[en%k]); int mx = -1; if(akt == en/k)return bb[en%k]; for(int i = 15;i>=0;i--){ if(nm[akt*k][i][0]/k <= en/k){ //printf("test %d %d\n",i,nm[akt*k][i][0]/k); for(int j1 = 0;j1<k;j1++){ nxt[j1] = -1; for(int j2 = 0;j2<k;j2++){ if(bb[j2] != -1 && bst[akt*k+j2][i][j1] != -1){ int tmp = bb[j2] + bst[akt*k+j2][i][j1]; if(nxt[j1] == -1 ||nxt[j1] > tmp)nxt[j1] = tmp; }; }; }; for(int j = 0;j<k;j++)bb[j] = nxt[j]; return solve(nm[akt*k][i][0]/k,en); break; }; }; }; int calc(int st, int p, int jk){ if(st > n){ return -1; }; if(bst[st][p][jk])return bst[st][p][jk]; if(p == 0){ if(adj[st][jk])bst[st][p][jk] = adj[st][jk]; else bst[st][p][jk] = -1; nm[st][p][jk] = (st/k + 1)*k + jk; return bst[st][p][jk]; }else{ int mx = -1; for(int i = 0;i<k;i++){ int tmp1 = calc(st,p-1,i); int tmp2; tmp2 = calc(nm[st][p-1][i],p-1,jk); if(tmp1 != -1){ if(tmp2 != -1){ if(mx == -1 || mx > tmp1 + tmp2){ mx = tmp1 + tmp2; }; }; }; }; bst[st][p][jk] = mx; nm[st][p][jk] = (st/k + (1 << p)) * k + jk; return bst[st][p][jk]; }; }; int main(void){ int m,o; scanf("%d %d %d %d",&k,&n,&m,&o); int a,b,t; for(int i = 0;i<m;i++){ scanf("%d %d %d",&a,&b,&t); adj[a][b%k] = t; }; for(int i = 0;i<16;i++){ for(int j = 0;j<k;j++){ for(int l = 0;l<n;l++){ int tmp = calc(l,i,j); //printf("%d %d %d %d %d\n",l,j,i,tmp,nm[l][i][j]); }; }; }; for(int i = 0;i<o;i++){ scanf("%d %d",&a,&b); for(int j = 0;j<k;j++){ bb[j] = -1; }; bb[a%k] = 0; printf("%d\n",solve(a/k,b)); }; return 0; };

Compilation message (stderr)

toll.cpp: In function 'int solve(int, int)':
toll.cpp:15:7: warning: unused variable 'mx' [-Wunused-variable]
   int mx = -1;
       ^~
toll.cpp: In function 'int main()':
toll.cpp:77:13: warning: unused variable 'tmp' [-Wunused-variable]
         int tmp = calc(l,i,j);  
             ^~~
toll.cpp: In function 'int solve(int, int)':
toll.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
 };
 ^
toll.cpp: In function 'int main()':
toll.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d",&k,&n,&m,&o);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&a,&b,&t);  
     ~~~~~^~~~~~~~~~~~~~~~~~~~~
toll.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&a,&b);
     ~~~~~^~~~~~~~~~~~~~~
#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...