Submission #676493

# Submission time Handle Problem Language Result Execution time Memory
676493 2022-12-31T03:43:24 Z penguin133 Toll (BOI17_toll) C++17
100 / 100
311 ms 32588 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> > 
#define fi first
#define se second
int n,m,q,k;
struct bru{
	int d[5][5];
};
vector<pi>v[200005];
struct node{
	int s,e,m;
	bru val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e)/2;
		if(s != e){
			l = new node(s, m);
			r = new node(m+1, e);
			for(int i=0;i<k;i++){
				for(int j=0;j<k;j++){
					val.d[i][j] = 1e18;
					for(int x=0;x<k;x++){
						int mid = m*k + x;
						for(auto [a, b] : v[mid]){
							int tmp = a%k;
							val.d[i][j] = min(val.d[i][j], l->val.d[i][x] + r->val.d[tmp][j] + b);
						}
					}
				}
			}
		}
		else{
			for(int i=0;i<5;i++)for(int j=0;j<5;j++)val.d[i][j] = 1e18;
			for(int i=0;i<k;i++)val.d[i][i] = 0;
		}
	}
	bru query(int S, int E){
		if(s == S && e == E)return val;
		else if(E <= m)return l->query(S, E);
		else if(S > m)return r->query(S, E);
		else{
			bru left = l->query(S, m);
			bru right = r->query(m+1, E);
			bru ans;
			for(int i=0;i<k;i++){
				for(int j=0;j<k;j++){
					ans.d[i][j] = 1e18;
					for(int x=0;x<k;x++){
						int mid = m*k + x;
						for(auto [a, b] : v[mid]){
							int tmp = a%k;
							ans.d[i][j] = min(ans.d[i][j], left.d[i][x] + right.d[tmp][j] + b);
						}
					}
				}
			}
			return ans;
		}
	}
}*root;

void solve(){
	cin >> k >> n >> m >> q;
	while(m--){
		int a,b,c;cin >> a >> b >> c;
		v[a].push_back({b, c});
	}
	root = new node(0, (n + k - 1)/k);
	while(q--){
		int l, r;cin >> l >> r;
		bru ans = root->query(l/k, r/k);
		cout << (ans.d[l%k][r%k] == 1e18 ? -1 : ans.d[l%k][r%k]) << '\n';
	}
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

Compilation message

toll.cpp:79:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   79 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 49 ms 32588 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5012 KB Output is correct
5 Correct 4 ms 5548 KB Output is correct
6 Correct 5 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 51 ms 32532 KB Output is correct
9 Correct 50 ms 32452 KB Output is correct
10 Correct 31 ms 30188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 21628 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5016 KB Output is correct
7 Correct 7 ms 5588 KB Output is correct
8 Correct 10 ms 5368 KB Output is correct
9 Correct 41 ms 32496 KB Output is correct
10 Correct 101 ms 19580 KB Output is correct
11 Correct 63 ms 21796 KB Output is correct
12 Correct 61 ms 16692 KB Output is correct
13 Correct 139 ms 15180 KB Output is correct
14 Correct 51 ms 14096 KB Output is correct
15 Correct 72 ms 11360 KB Output is correct
16 Correct 72 ms 11212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5548 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 6 ms 5292 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 41 ms 32296 KB Output is correct
11 Correct 45 ms 21536 KB Output is correct
12 Correct 61 ms 19400 KB Output is correct
13 Correct 72 ms 20088 KB Output is correct
14 Correct 51 ms 18280 KB Output is correct
15 Correct 43 ms 11212 KB Output is correct
16 Correct 41 ms 11088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5548 KB Output is correct
7 Correct 4 ms 5332 KB Output is correct
8 Correct 6 ms 5292 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 41 ms 32296 KB Output is correct
11 Correct 45 ms 21536 KB Output is correct
12 Correct 61 ms 19400 KB Output is correct
13 Correct 72 ms 20088 KB Output is correct
14 Correct 51 ms 18280 KB Output is correct
15 Correct 43 ms 11212 KB Output is correct
16 Correct 41 ms 11088 KB Output is correct
17 Correct 53 ms 21680 KB Output is correct
18 Correct 3 ms 5016 KB Output is correct
19 Correct 3 ms 5020 KB Output is correct
20 Correct 3 ms 4948 KB Output is correct
21 Correct 4 ms 4948 KB Output is correct
22 Correct 3 ms 5020 KB Output is correct
23 Correct 5 ms 5588 KB Output is correct
24 Correct 8 ms 5332 KB Output is correct
25 Correct 45 ms 5308 KB Output is correct
26 Correct 22 ms 5204 KB Output is correct
27 Correct 39 ms 32392 KB Output is correct
28 Correct 89 ms 19568 KB Output is correct
29 Correct 90 ms 20172 KB Output is correct
30 Correct 72 ms 18372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 32588 KB Output is correct
2 Correct 3 ms 5020 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 4 ms 5012 KB Output is correct
5 Correct 4 ms 5548 KB Output is correct
6 Correct 5 ms 5460 KB Output is correct
7 Correct 4 ms 5460 KB Output is correct
8 Correct 51 ms 32532 KB Output is correct
9 Correct 50 ms 32452 KB Output is correct
10 Correct 31 ms 30188 KB Output is correct
11 Correct 60 ms 21628 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 5016 KB Output is correct
17 Correct 7 ms 5588 KB Output is correct
18 Correct 10 ms 5368 KB Output is correct
19 Correct 41 ms 32496 KB Output is correct
20 Correct 101 ms 19580 KB Output is correct
21 Correct 63 ms 21796 KB Output is correct
22 Correct 61 ms 16692 KB Output is correct
23 Correct 139 ms 15180 KB Output is correct
24 Correct 51 ms 14096 KB Output is correct
25 Correct 72 ms 11360 KB Output is correct
26 Correct 72 ms 11212 KB Output is correct
27 Correct 3 ms 4948 KB Output is correct
28 Correct 3 ms 5020 KB Output is correct
29 Correct 2 ms 4948 KB Output is correct
30 Correct 3 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 5548 KB Output is correct
33 Correct 4 ms 5332 KB Output is correct
34 Correct 6 ms 5292 KB Output is correct
35 Correct 5 ms 5204 KB Output is correct
36 Correct 41 ms 32296 KB Output is correct
37 Correct 45 ms 21536 KB Output is correct
38 Correct 61 ms 19400 KB Output is correct
39 Correct 72 ms 20088 KB Output is correct
40 Correct 51 ms 18280 KB Output is correct
41 Correct 43 ms 11212 KB Output is correct
42 Correct 41 ms 11088 KB Output is correct
43 Correct 53 ms 21680 KB Output is correct
44 Correct 3 ms 5016 KB Output is correct
45 Correct 3 ms 5020 KB Output is correct
46 Correct 3 ms 4948 KB Output is correct
47 Correct 4 ms 4948 KB Output is correct
48 Correct 3 ms 5020 KB Output is correct
49 Correct 5 ms 5588 KB Output is correct
50 Correct 8 ms 5332 KB Output is correct
51 Correct 45 ms 5308 KB Output is correct
52 Correct 22 ms 5204 KB Output is correct
53 Correct 39 ms 32392 KB Output is correct
54 Correct 89 ms 19568 KB Output is correct
55 Correct 90 ms 20172 KB Output is correct
56 Correct 72 ms 18372 KB Output is correct
57 Correct 311 ms 18964 KB Output is correct
58 Correct 51 ms 32532 KB Output is correct
59 Correct 71 ms 21876 KB Output is correct