Submission #985388

# Submission time Handle Problem Language Result Execution time Memory
985388 2024-05-17T17:22:17 Z OAleksa Toll (BOI17_toll) C++14
100 / 100
158 ms 16212 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N = 5e4 + 69;
const int inf = 1e12;
int n, m, k, q, dis[N][6], d[N];
vector<pair<int, int>> g[N];
vector<pair<int, int>> dd[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> k >> n >> m >> q;
  	const int B = 100 * k;
  	for (int i = 1;i <= m;i++) {
  		int a, b, c;
  		cin >> a >> b >> c;
  		g[a].push_back({b, c});
  	}
  	for (int i = 0;i < n;i++) {
  		int en = (i / B + 1) * B;
  		d[i] = 0;
  		for (int j = i + 1;j < en + k;j++)
  			d[j] = inf;
  		for (int j = i;j < en + k;j++) {
  			for (auto u : g[j]) {
  				d[u.f] = min(d[u.f], d[j] + u.s);
  			}
  		}
  		for (int j = en + k - 1;j >= en;j--)
  			dd[i].push_back({j, d[j]});
  	}
  	while (q--) {
  		int a, b;
  		cin >> a >> b;
  		int x = (b / B) * B;
  		for (int j = x;j <= b;j++)
  			d[j] = inf;
  		for (int j = a;j < a + k;j++)
  			d[j] = inf;
  		d[a] = 0;
  		while (a / B != b / B) {	
  			int en = (a / B + 1) * B;
  			for (int j = en;j < en + k;j++)
  				d[j] = inf;
  			for (int j = a;j < a + k;j++) {
  				for (auto u : dd[j])
  					d[u.f] = inf;
  			}
  			for (int j = a;j < a + k;j++) {
  				for (auto u : dd[j])
  					d[u.f] = min(d[u.f], d[j] + u.s);
  			}
  			a = en;
  		}
			for (int i = a;i < b;i++) {
				for (auto u : g[i])
					d[u.f] = min(d[u.f], d[i] + u.s);
			}
			if (d[b] >= inf)
				cout << "-1\n";
			else
				cout << d[b] << '\n';
		}
  }
  return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 7760 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 39 ms 8804 KB Output is correct
9 Correct 35 ms 8540 KB Output is correct
10 Correct 17 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9632 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 5 ms 4700 KB Output is correct
8 Correct 7 ms 4956 KB Output is correct
9 Correct 40 ms 8776 KB Output is correct
10 Correct 111 ms 14676 KB Output is correct
11 Correct 70 ms 11600 KB Output is correct
12 Correct 88 ms 11924 KB Output is correct
13 Correct 114 ms 15952 KB Output is correct
14 Correct 56 ms 11092 KB Output is correct
15 Correct 69 ms 12116 KB Output is correct
16 Correct 77 ms 12172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 24 ms 8436 KB Output is correct
11 Correct 47 ms 11088 KB Output is correct
12 Correct 97 ms 14680 KB Output is correct
13 Correct 85 ms 15380 KB Output is correct
14 Correct 67 ms 13396 KB Output is correct
15 Correct 62 ms 12116 KB Output is correct
16 Correct 60 ms 11956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 5 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 24 ms 8436 KB Output is correct
11 Correct 47 ms 11088 KB Output is correct
12 Correct 97 ms 14680 KB Output is correct
13 Correct 85 ms 15380 KB Output is correct
14 Correct 67 ms 13396 KB Output is correct
15 Correct 62 ms 12116 KB Output is correct
16 Correct 60 ms 11956 KB Output is correct
17 Correct 52 ms 11092 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4700 KB Output is correct
22 Correct 1 ms 4700 KB Output is correct
23 Correct 3 ms 4760 KB Output is correct
24 Correct 4 ms 4700 KB Output is correct
25 Correct 8 ms 4956 KB Output is correct
26 Correct 5 ms 4964 KB Output is correct
27 Correct 27 ms 8540 KB Output is correct
28 Correct 85 ms 14732 KB Output is correct
29 Correct 89 ms 15424 KB Output is correct
30 Correct 74 ms 13652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 7760 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 2 ms 4700 KB Output is correct
8 Correct 39 ms 8804 KB Output is correct
9 Correct 35 ms 8540 KB Output is correct
10 Correct 17 ms 6488 KB Output is correct
11 Correct 69 ms 9632 KB Output is correct
12 Correct 1 ms 4696 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 1 ms 4696 KB Output is correct
17 Correct 5 ms 4700 KB Output is correct
18 Correct 7 ms 4956 KB Output is correct
19 Correct 40 ms 8776 KB Output is correct
20 Correct 111 ms 14676 KB Output is correct
21 Correct 70 ms 11600 KB Output is correct
22 Correct 88 ms 11924 KB Output is correct
23 Correct 114 ms 15952 KB Output is correct
24 Correct 56 ms 11092 KB Output is correct
25 Correct 69 ms 12116 KB Output is correct
26 Correct 77 ms 12172 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 1 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 1 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 2 ms 4696 KB Output is correct
34 Correct 5 ms 4956 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 24 ms 8436 KB Output is correct
37 Correct 47 ms 11088 KB Output is correct
38 Correct 97 ms 14680 KB Output is correct
39 Correct 85 ms 15380 KB Output is correct
40 Correct 67 ms 13396 KB Output is correct
41 Correct 62 ms 12116 KB Output is correct
42 Correct 60 ms 11956 KB Output is correct
43 Correct 52 ms 11092 KB Output is correct
44 Correct 1 ms 4696 KB Output is correct
45 Correct 1 ms 4700 KB Output is correct
46 Correct 1 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 1 ms 4700 KB Output is correct
49 Correct 3 ms 4760 KB Output is correct
50 Correct 4 ms 4700 KB Output is correct
51 Correct 8 ms 4956 KB Output is correct
52 Correct 5 ms 4964 KB Output is correct
53 Correct 27 ms 8540 KB Output is correct
54 Correct 85 ms 14732 KB Output is correct
55 Correct 89 ms 15424 KB Output is correct
56 Correct 74 ms 13652 KB Output is correct
57 Correct 158 ms 16212 KB Output is correct
58 Correct 40 ms 8808 KB Output is correct
59 Correct 70 ms 11348 KB Output is correct