Submission #245144

# Submission time Handle Problem Language Result Execution time Memory
245144 2020-07-05T15:06:54 Z m3r8 Toll (BOI17_toll) C++14
0 / 100
178 ms 69880 KB
#include <stdio.h>


#define N 50100

int bst[N][17][5];
int nm[N][17][5];
int adj[N][5];

int k;
int solve(int st, int en){
  int mx = -1;
  if(st == en)return 0;  
  if(st/k == en/k)return -1;
  for(int i = 16;i>=0;i--){
    if(nm[st][i][0]/k <= en/k){
      for(int j = 0;j<k;j++){
        int tmp = solve(nm[st][i][j],en);  
        if(tmp != -1){
          if(bst[st][i][j] != -1){
            if(mx == -1 || mx > bst[st][i][j] + tmp){
              mx = bst[st][i][j] + tmp;  
            };
          };  
        };
      };
      break;
    };
  };
  return mx;
};

int calc(int st, int p, int jk){
  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] = nm[nm[st][p-1][0]][p-1][jk];
    return bst[st][p][jk];
  };
};

int main(void){
  int n,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<17;i++){
    for(int j = 0;j<k;j++){
      for(int l = 0;l<n;l++){
        calc(l,i,k);  
      };
    };  
  };
  for(int i = 0;i<o;i++){
    scanf("%d %d",&a,&b);
    printf("%d\n",solve(a,b));
  };
  return 0;
};

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:62: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:65: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:76: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 time Memory Grader output
1 Runtime error 143 ms 69880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 178 ms 69880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 67960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 72 ms 67960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 143 ms 69880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -