Submission #244646

# Submission time Handle Problem Language Result Execution time Memory
244646 2020-07-04T13:30:26 Z TheLorax Toll (BOI17_toll) C++11
100 / 100
185 ms 25592 KB
#include <bits/stdc++.h>

//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")

#define F first
#define S second
#define MT make_tuple
#define MP make_pair
#define SZ(a) ((int)(a).size())
#define PB push_back
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)
#define ALL(a) (a).begin(), (a).end()
#define END(s) {cout << s;return;}

using namespace std;

typedef long long ll;
typedef pair<ll, ll> ii;

int main(){
  int k, n, m, o;
  scanf("%d %d %d %d", &k,&n,&m,&o);
  n=k*((n+k-1)/k);
  int lgn=0;
  while ((1<<lgn)*k<=n)
    lgn++;
  ll dis[n][k][lgn];
  for(int i=0; i<n; i++)
    for(int j=0; j<k; j++)
      for(int l=0; l<lgn; l++)
        dis[i][j][l]=INT_MAX*10LL;
  for(int i=0; i<m; i++){
    int a, b, t; scanf("%d %d %d", &a, &b, &t);
    dis[a][b%k][0]=t;
  }
  for(int l=1; l<lgn; l++)
    for(int i=0; i<n; i++)
      for(int j=0; j<k; j++)
        for(int p=0; p<k; p++)
          if(p+k*(i/k+(1<<(l-1)))<n)
            dis[i][j][l]=min(dis[i][j][l], dis[i][p][l-1]+dis[p+k*(i/k+(1<<(l-1)))][j][l-1]);
  for(int q=0; q<o; q++){
    int a, b; scanf("%d %d", &a, &b);
    int d=b/k-a/k;
    if(d<1){
      printf("-1\n");
      continue;
    }
    std::vector<ll> t(k, INT_MAX*10LL), t2(k,INT_MAX*10LL);
    t2[a%k]=0;
    a-=a%k;
    for(int i=20; i>=0; i--){
      if(!((1<<i)&d))
        continue;
      for(int j=0; j<k; j++)
        for(int p=0; p<k; p++)
          t[j]=min(t[j], t2[p]+dis[p+a][j][i]);
      a+=(1<<i)*k;
      for(int j=0; j<k; j++){
        t2[j]=t[j];
        t[j]=INT_MAX*10LL;
      }
    }
    if(t2[b%k]>INT_MAX)
      t2[b%k]=-1;
    printf("%lld\n", t2[b%k]);
  }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:25: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:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int a, b, t; scanf("%d %d %d", &a, &b, &t);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int a, b; scanf("%d %d", &a, &b);
               ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 6648 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 46 ms 6648 KB Output is correct
9 Correct 45 ms 6648 KB Output is correct
10 Correct 25 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 12152 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 12 ms 384 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 48 ms 6648 KB Output is correct
10 Correct 119 ms 18040 KB Output is correct
11 Correct 92 ms 12152 KB Output is correct
12 Correct 92 ms 18040 KB Output is correct
13 Correct 129 ms 15668 KB Output is correct
14 Correct 83 ms 10240 KB Output is correct
15 Correct 113 ms 15616 KB Output is correct
16 Correct 107 ms 15616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 38 ms 6528 KB Output is correct
11 Correct 90 ms 12032 KB Output is correct
12 Correct 109 ms 17920 KB Output is correct
13 Correct 116 ms 17920 KB Output is correct
14 Correct 104 ms 18120 KB Output is correct
15 Correct 90 ms 15616 KB Output is correct
16 Correct 97 ms 15616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 38 ms 6528 KB Output is correct
11 Correct 90 ms 12032 KB Output is correct
12 Correct 109 ms 17920 KB Output is correct
13 Correct 116 ms 17920 KB Output is correct
14 Correct 104 ms 18120 KB Output is correct
15 Correct 90 ms 15616 KB Output is correct
16 Correct 97 ms 15616 KB Output is correct
17 Correct 81 ms 12032 KB Output is correct
18 Correct 5 ms 256 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 256 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 9 ms 512 KB Output is correct
24 Correct 7 ms 512 KB Output is correct
25 Correct 10 ms 768 KB Output is correct
26 Correct 8 ms 640 KB Output is correct
27 Correct 44 ms 7544 KB Output is correct
28 Correct 115 ms 20216 KB Output is correct
29 Correct 134 ms 20472 KB Output is correct
30 Correct 105 ms 19832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 6648 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 46 ms 6648 KB Output is correct
9 Correct 45 ms 6648 KB Output is correct
10 Correct 25 ms 6656 KB Output is correct
11 Correct 86 ms 12152 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 12 ms 384 KB Output is correct
18 Correct 11 ms 512 KB Output is correct
19 Correct 48 ms 6648 KB Output is correct
20 Correct 119 ms 18040 KB Output is correct
21 Correct 92 ms 12152 KB Output is correct
22 Correct 92 ms 18040 KB Output is correct
23 Correct 129 ms 15668 KB Output is correct
24 Correct 83 ms 10240 KB Output is correct
25 Correct 113 ms 15616 KB Output is correct
26 Correct 107 ms 15616 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 256 KB Output is correct
30 Correct 5 ms 256 KB Output is correct
31 Correct 4 ms 256 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 7 ms 640 KB Output is correct
35 Correct 8 ms 512 KB Output is correct
36 Correct 38 ms 6528 KB Output is correct
37 Correct 90 ms 12032 KB Output is correct
38 Correct 109 ms 17920 KB Output is correct
39 Correct 116 ms 17920 KB Output is correct
40 Correct 104 ms 18120 KB Output is correct
41 Correct 90 ms 15616 KB Output is correct
42 Correct 97 ms 15616 KB Output is correct
43 Correct 81 ms 12032 KB Output is correct
44 Correct 5 ms 256 KB Output is correct
45 Correct 5 ms 256 KB Output is correct
46 Correct 5 ms 256 KB Output is correct
47 Correct 5 ms 256 KB Output is correct
48 Correct 5 ms 256 KB Output is correct
49 Correct 9 ms 512 KB Output is correct
50 Correct 7 ms 512 KB Output is correct
51 Correct 10 ms 768 KB Output is correct
52 Correct 8 ms 640 KB Output is correct
53 Correct 44 ms 7544 KB Output is correct
54 Correct 115 ms 20216 KB Output is correct
55 Correct 134 ms 20472 KB Output is correct
56 Correct 105 ms 19832 KB Output is correct
57 Correct 185 ms 25592 KB Output is correct
58 Correct 46 ms 7544 KB Output is correct
59 Correct 91 ms 13944 KB Output is correct