Submission #135704

# Submission time Handle Problem Language Result Execution time Memory
135704 2019-07-24T09:55:05 Z khsoo01 Toll (BOI17_toll) C++11
100 / 100
119 ms 17836 KB
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int s, n, m, o;

struct way {
	int t[5][5];
	way() {
		for(int i=0;i<5;i++) {
			for(int j=0;j<5;j++) {
				t[i][j] = inf;
			}
		}
	}
	way operator + (way T) {
		way ret;
		for(int i=0;i<s;i++) {
			for(int j=0;j<s;j++) {
				for(int k=0;k<s;k++) {
					ret.t[i][j] = min(ret.t[i][j], t[i][k]+T.t[k][j]);
				}
			}
		}
		return ret;
	}
};

struct segtree {
	way val[144444];
	int lim;
	void init () {
		for(lim = 1; lim <= n/s; lim <<= 1);
	}
	void update (int S, int E, int V) {
		val[lim+S/s].t[S%s][E%s] = V;
	}
	void buildup () {
		for(int i = lim; --i; ) {
			val[i] = val[2*i] + val[2*i+1];
		}
	}
	int query (int S, int E) {
		if(S == E) return 0;
		if(S/s >= E/s) return inf;
		way ra, rb, ret;
		for(int i=0;i<s;i++) {
			ra.t[i][i] = rb.t[i][i] = 0;
		}
		int SS = lim + S/s, SE = lim + E/s - 1;
		while(SS <= SE) {
			if(SS%2 == 1) {ra = ra + val[SS]; SS++;}
			if(SE%2 == 0) {rb = val[SE] + rb; SE--;}
			SS >>= 1; SE >>= 1;
		}
		ret = ra + rb;
		return ret.t[S%s][E%s];
	}
} seg;

int main()
{
	scanf("%d%d%d%d",&s,&n,&m,&o);
	seg.init();
	for(int i=1;i<=m;i++) {
		int A, B, C;
		scanf("%d%d%d",&A,&B,&C);
		seg.update(A, B, C);
	}
	seg.buildup();
	while(o--) {
		int S, E;
		scanf("%d%d",&S,&E);
		int ret = seg.query(S,E);
		printf("%d\n",ret == inf ? -1 : ret);
	}
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&s,&n,&m,&o);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&A,&B,&C);
   ~~~~~^~~~~~~~~~~~~~~~~~~
toll.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&S,&E);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 53 ms 15608 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 14 ms 14500 KB Output is correct
5 Correct 16 ms 14456 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 54 ms 15520 KB Output is correct
9 Correct 51 ms 15352 KB Output is correct
10 Correct 28 ms 14584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 16136 KB Output is correct
2 Correct 14 ms 14460 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 17 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 14 ms 14456 KB Output is correct
7 Correct 20 ms 14584 KB Output is correct
8 Correct 21 ms 14584 KB Output is correct
9 Correct 48 ms 15352 KB Output is correct
10 Correct 87 ms 16892 KB Output is correct
11 Correct 69 ms 16248 KB Output is correct
12 Correct 67 ms 15736 KB Output is correct
13 Correct 83 ms 16940 KB Output is correct
14 Correct 55 ms 15864 KB Output is correct
15 Correct 51 ms 15736 KB Output is correct
16 Correct 51 ms 15608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 17 ms 14456 KB Output is correct
4 Correct 16 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 16 ms 14584 KB Output is correct
9 Correct 16 ms 14456 KB Output is correct
10 Correct 41 ms 15196 KB Output is correct
11 Correct 58 ms 15996 KB Output is correct
12 Correct 77 ms 16656 KB Output is correct
13 Correct 82 ms 16908 KB Output is correct
14 Correct 66 ms 16248 KB Output is correct
15 Correct 47 ms 15740 KB Output is correct
16 Correct 46 ms 15612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 14456 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 17 ms 14456 KB Output is correct
4 Correct 16 ms 14456 KB Output is correct
5 Correct 14 ms 14456 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 16 ms 14584 KB Output is correct
9 Correct 16 ms 14456 KB Output is correct
10 Correct 41 ms 15196 KB Output is correct
11 Correct 58 ms 15996 KB Output is correct
12 Correct 77 ms 16656 KB Output is correct
13 Correct 82 ms 16908 KB Output is correct
14 Correct 66 ms 16248 KB Output is correct
15 Correct 47 ms 15740 KB Output is correct
16 Correct 46 ms 15612 KB Output is correct
17 Correct 62 ms 16120 KB Output is correct
18 Correct 18 ms 14456 KB Output is correct
19 Correct 14 ms 14456 KB Output is correct
20 Correct 15 ms 14584 KB Output is correct
21 Correct 14 ms 14456 KB Output is correct
22 Correct 14 ms 14456 KB Output is correct
23 Correct 17 ms 14456 KB Output is correct
24 Correct 17 ms 14456 KB Output is correct
25 Correct 21 ms 14584 KB Output is correct
26 Correct 19 ms 14456 KB Output is correct
27 Correct 43 ms 15364 KB Output is correct
28 Correct 85 ms 16644 KB Output is correct
29 Correct 84 ms 16888 KB Output is correct
30 Correct 68 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 15608 KB Output is correct
2 Correct 14 ms 14456 KB Output is correct
3 Correct 14 ms 14456 KB Output is correct
4 Correct 14 ms 14500 KB Output is correct
5 Correct 16 ms 14456 KB Output is correct
6 Correct 15 ms 14456 KB Output is correct
7 Correct 15 ms 14456 KB Output is correct
8 Correct 54 ms 15520 KB Output is correct
9 Correct 51 ms 15352 KB Output is correct
10 Correct 28 ms 14584 KB Output is correct
11 Correct 66 ms 16136 KB Output is correct
12 Correct 14 ms 14460 KB Output is correct
13 Correct 14 ms 14456 KB Output is correct
14 Correct 17 ms 14456 KB Output is correct
15 Correct 14 ms 14456 KB Output is correct
16 Correct 14 ms 14456 KB Output is correct
17 Correct 20 ms 14584 KB Output is correct
18 Correct 21 ms 14584 KB Output is correct
19 Correct 48 ms 15352 KB Output is correct
20 Correct 87 ms 16892 KB Output is correct
21 Correct 69 ms 16248 KB Output is correct
22 Correct 67 ms 15736 KB Output is correct
23 Correct 83 ms 16940 KB Output is correct
24 Correct 55 ms 15864 KB Output is correct
25 Correct 51 ms 15736 KB Output is correct
26 Correct 51 ms 15608 KB Output is correct
27 Correct 14 ms 14456 KB Output is correct
28 Correct 14 ms 14456 KB Output is correct
29 Correct 17 ms 14456 KB Output is correct
30 Correct 16 ms 14456 KB Output is correct
31 Correct 14 ms 14456 KB Output is correct
32 Correct 15 ms 14456 KB Output is correct
33 Correct 15 ms 14456 KB Output is correct
34 Correct 16 ms 14584 KB Output is correct
35 Correct 16 ms 14456 KB Output is correct
36 Correct 41 ms 15196 KB Output is correct
37 Correct 58 ms 15996 KB Output is correct
38 Correct 77 ms 16656 KB Output is correct
39 Correct 82 ms 16908 KB Output is correct
40 Correct 66 ms 16248 KB Output is correct
41 Correct 47 ms 15740 KB Output is correct
42 Correct 46 ms 15612 KB Output is correct
43 Correct 62 ms 16120 KB Output is correct
44 Correct 18 ms 14456 KB Output is correct
45 Correct 14 ms 14456 KB Output is correct
46 Correct 15 ms 14584 KB Output is correct
47 Correct 14 ms 14456 KB Output is correct
48 Correct 14 ms 14456 KB Output is correct
49 Correct 17 ms 14456 KB Output is correct
50 Correct 17 ms 14456 KB Output is correct
51 Correct 21 ms 14584 KB Output is correct
52 Correct 19 ms 14456 KB Output is correct
53 Correct 43 ms 15364 KB Output is correct
54 Correct 85 ms 16644 KB Output is correct
55 Correct 84 ms 16888 KB Output is correct
56 Correct 68 ms 16248 KB Output is correct
57 Correct 119 ms 17836 KB Output is correct
58 Correct 57 ms 15404 KB Output is correct
59 Correct 83 ms 16252 KB Output is correct