Submission #714523

# Submission time Handle Problem Language Result Execution time Memory
714523 2023-03-24T21:38:29 Z lukameladze Toll (BOI17_toll) C++14
100 / 100
332 ms 14024 KB
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
// #define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 2e5 + 5, inf = 1e9;
int t,n,k,a[N], m, q, x;
struct nod{
	int x[5][5];
};
nod zer_vii, inf_vii, tree[N];
nod merge(nod a, nod b) {
	nod res;
	res  = inf_vii;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			for (int m = 0; m < k; m++) {
				res.x[i][j] = min(res.x[i][j], a.x[i][m] + b.x[m][j]);
			}
		}
	}
	return res;
}
void build(int node, int le, int ri) {
	tree[node] = inf_vii;
	if (le == ri) {
		return ;
	}
	int mid = (le + ri) / 2;
	build(2 * node, le, mid);
	build(2 * node + 1, mid + 1, ri);
}
void update(int node, int le, int ri, int idxa, int rema, int idxb, int remb, int val) {
	if (le > idxa || ri < idxa) return ;
	if (le == ri) {
		tree[node].x[rema][remb] = min(tree[node].x[rema][remb], val);
		return ;
	}
	int mid = (le + ri) / 2;
	update(2 * node, le, mid, idxa, rema, idxb, remb, val);
	update(2 * node + 1, mid + 1, ri, idxa, rema, idxb, remb, val);
	tree[node] = merge(tree[2 * node], tree[2 * node + 1]);
}
nod getans(int node, int le, int ri, int start, int end) {
	if (le > end || ri < start) return zer_vii;
	if (le >= start && ri <= end) {
		return tree[node];	
	}
	int mid = (le + ri) / 2;
	nod p1, p2, res;
	p1 = getans(2 * node, le, mid, start, end); p2 = getans(2 * node + 1, mid + 1, ri, start, end);
	res = merge(p1, p2);
	return res;
}
main() {
	std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>k>>n>>m>>q;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			zer_vii.x[i][j] = inf; inf_vii.x[i][j] = inf;
		}
	}
	for (int i = 0; i < k; i++) zer_vii.x[i][i] = 0;
	build(1, 0, (n - 1) / k);
	for (int i = 1; i <= m; i++) {
		int a, b, x;
		cin>>a>>b>>x;
		update(1, 0, (n - 1) / k, a / k, a % k, b / k, b % k, x);
	}
	while (q--) {
		int a, b;
		cin>>a>>b;
		nod ans; 
		ans = getans(1, 0, (n - 1) / k, a / k, b / k - 1);
		cout<<(ans.x[a % k][b % k] < inf ? ans.x[a % k][b % k] : -1)<<"\n";
	}
}

Compilation message

toll.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 75 ms 13144 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 76 ms 13156 KB Output is correct
9 Correct 61 ms 13148 KB Output is correct
10 Correct 22 ms 13236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 6744 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 6 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 57 ms 13144 KB Output is correct
10 Correct 146 ms 4888 KB Output is correct
11 Correct 99 ms 6740 KB Output is correct
12 Correct 91 ms 4788 KB Output is correct
13 Correct 328 ms 1920 KB Output is correct
14 Correct 94 ms 3532 KB Output is correct
15 Correct 206 ms 1928 KB Output is correct
16 Correct 171 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 52 ms 13144 KB Output is correct
11 Correct 81 ms 6740 KB Output is correct
12 Correct 136 ms 4788 KB Output is correct
13 Correct 155 ms 4692 KB Output is correct
14 Correct 130 ms 4804 KB Output is correct
15 Correct 156 ms 1876 KB Output is correct
16 Correct 163 ms 1932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 8 ms 384 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 52 ms 13144 KB Output is correct
11 Correct 81 ms 6740 KB Output is correct
12 Correct 136 ms 4788 KB Output is correct
13 Correct 155 ms 4692 KB Output is correct
14 Correct 130 ms 4804 KB Output is correct
15 Correct 156 ms 1876 KB Output is correct
16 Correct 163 ms 1932 KB Output is correct
17 Correct 91 ms 6740 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 3 ms 544 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 12 ms 388 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 55 ms 13160 KB Output is correct
28 Correct 151 ms 4792 KB Output is correct
29 Correct 223 ms 4788 KB Output is correct
30 Correct 139 ms 4784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 13144 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 76 ms 13156 KB Output is correct
9 Correct 61 ms 13148 KB Output is correct
10 Correct 22 ms 13236 KB Output is correct
11 Correct 99 ms 6744 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 6 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 57 ms 13144 KB Output is correct
20 Correct 146 ms 4888 KB Output is correct
21 Correct 99 ms 6740 KB Output is correct
22 Correct 91 ms 4788 KB Output is correct
23 Correct 328 ms 1920 KB Output is correct
24 Correct 94 ms 3532 KB Output is correct
25 Correct 206 ms 1928 KB Output is correct
26 Correct 171 ms 1920 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 2 ms 536 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 8 ms 384 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 52 ms 13144 KB Output is correct
37 Correct 81 ms 6740 KB Output is correct
38 Correct 136 ms 4788 KB Output is correct
39 Correct 155 ms 4692 KB Output is correct
40 Correct 130 ms 4804 KB Output is correct
41 Correct 156 ms 1876 KB Output is correct
42 Correct 163 ms 1932 KB Output is correct
43 Correct 91 ms 6740 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 3 ms 544 KB Output is correct
50 Correct 3 ms 340 KB Output is correct
51 Correct 12 ms 388 KB Output is correct
52 Correct 7 ms 340 KB Output is correct
53 Correct 55 ms 13160 KB Output is correct
54 Correct 151 ms 4792 KB Output is correct
55 Correct 223 ms 4788 KB Output is correct
56 Correct 139 ms 4784 KB Output is correct
57 Correct 332 ms 6840 KB Output is correct
58 Correct 67 ms 14024 KB Output is correct
59 Correct 114 ms 8636 KB Output is correct