Submission #486128

# Submission time Handle Problem Language Result Execution time Memory
486128 2021-11-10T15:09:58 Z Koosha_mv Toll (BOI17_toll) C++14
100 / 100
339 ms 106808 KB
#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first

const int N=1e5+9,sq=500,K=5,inf=1e9;

int n,k,m,q,a[N],dp[N],dist[N][sq];
vector<pair<int,int> > g[N];

void tsft(int u,int v){
	f(i,v*k,v*k+k) dp[i]=inf;
	f(i,u*k,u*k+k){
		f(j,v*k,v*k+k){
			minm(dp[j],dp[i]+dist[i][j-i]);
		}
	}	
}

main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>k>>n>>m>>q;
	f(i,0,m){
		int u,v,t;
		cin>>u>>v>>t;
		g[u].pb(mp(v,t));
	}
	f_(i,n-1,0){
		dist[i][0]=0;
		f(j,1,sq){
			dist[i][j]=inf;
			f(p,0,g[i].size()){
				if(g[i][p].F<=i+j){
					minm(dist[i][j],dist[g[i][p].F][j-(g[i][p].F-i)]+g[i][p].S);
				}
			}
		}
	}
	f(prt,0,q){
		int a,b,u,v;
		cin>>a>>b;
		u=a/k,v=b/k;
		f(i,u*k,u*k+k) dp[i]=inf;
		dp[a]=0;
		while(u!=v){
			int nxt=min(v,u+sq/k-1);
			tsft(u,nxt);
			u=nxt;
		}
		cout<<((dp[b] == inf || b<a) ? -1 : dp[b])<<'\n';
	}
}
/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13
*/

Compilation message

toll.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   34 | main(){
      | ^~~~
toll.cpp: In function 'int main()':
toll.cpp:7:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define f(i,a,b) for(int i=a;i<b;i++)
......
   46 |    f(p,0,g[i].size()){
      |      ~~~~~~~~~~~~~~~           
toll.cpp:46:4: note: in expansion of macro 'f'
   46 |    f(p,0,g[i].size()){
      |    ^
# Verdict Execution time Memory Grader output
1 Correct 120 ms 102340 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 4 ms 4556 KB Output is correct
6 Correct 5 ms 4556 KB Output is correct
7 Correct 4 ms 4556 KB Output is correct
8 Correct 115 ms 102192 KB Output is correct
9 Correct 112 ms 102156 KB Output is correct
10 Correct 91 ms 100688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 102228 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 5 ms 4684 KB Output is correct
8 Correct 7 ms 4812 KB Output is correct
9 Correct 112 ms 103132 KB Output is correct
10 Correct 223 ms 105496 KB Output is correct
11 Correct 177 ms 104004 KB Output is correct
12 Correct 151 ms 103364 KB Output is correct
13 Correct 223 ms 66572 KB Output is correct
14 Correct 152 ms 64724 KB Output is correct
15 Correct 124 ms 63980 KB Output is correct
16 Correct 125 ms 64000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 3 ms 4556 KB Output is correct
7 Correct 5 ms 4556 KB Output is correct
8 Correct 9 ms 4684 KB Output is correct
9 Correct 6 ms 4692 KB Output is correct
10 Correct 104 ms 102212 KB Output is correct
11 Correct 173 ms 102248 KB Output is correct
12 Correct 213 ms 103076 KB Output is correct
13 Correct 237 ms 103432 KB Output is correct
14 Correct 206 ms 102768 KB Output is correct
15 Correct 128 ms 62732 KB Output is correct
16 Correct 127 ms 62692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 1 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 3 ms 4556 KB Output is correct
7 Correct 5 ms 4556 KB Output is correct
8 Correct 9 ms 4684 KB Output is correct
9 Correct 6 ms 4692 KB Output is correct
10 Correct 104 ms 102212 KB Output is correct
11 Correct 173 ms 102248 KB Output is correct
12 Correct 213 ms 103076 KB Output is correct
13 Correct 237 ms 103432 KB Output is correct
14 Correct 206 ms 102768 KB Output is correct
15 Correct 128 ms 62732 KB Output is correct
16 Correct 127 ms 62692 KB Output is correct
17 Correct 167 ms 102272 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 1 ms 2636 KB Output is correct
22 Correct 1 ms 2636 KB Output is correct
23 Correct 4 ms 4684 KB Output is correct
24 Correct 5 ms 4684 KB Output is correct
25 Correct 8 ms 4684 KB Output is correct
26 Correct 7 ms 4684 KB Output is correct
27 Correct 113 ms 102272 KB Output is correct
28 Correct 223 ms 103164 KB Output is correct
29 Correct 231 ms 105800 KB Output is correct
30 Correct 190 ms 104644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 102340 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 4 ms 4556 KB Output is correct
6 Correct 5 ms 4556 KB Output is correct
7 Correct 4 ms 4556 KB Output is correct
8 Correct 115 ms 102192 KB Output is correct
9 Correct 112 ms 102156 KB Output is correct
10 Correct 91 ms 100688 KB Output is correct
11 Correct 186 ms 102228 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 5 ms 4684 KB Output is correct
18 Correct 7 ms 4812 KB Output is correct
19 Correct 112 ms 103132 KB Output is correct
20 Correct 223 ms 105496 KB Output is correct
21 Correct 177 ms 104004 KB Output is correct
22 Correct 151 ms 103364 KB Output is correct
23 Correct 223 ms 66572 KB Output is correct
24 Correct 152 ms 64724 KB Output is correct
25 Correct 124 ms 63980 KB Output is correct
26 Correct 125 ms 64000 KB Output is correct
27 Correct 1 ms 2636 KB Output is correct
28 Correct 1 ms 2636 KB Output is correct
29 Correct 1 ms 2636 KB Output is correct
30 Correct 1 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 3 ms 4556 KB Output is correct
33 Correct 5 ms 4556 KB Output is correct
34 Correct 9 ms 4684 KB Output is correct
35 Correct 6 ms 4692 KB Output is correct
36 Correct 104 ms 102212 KB Output is correct
37 Correct 173 ms 102248 KB Output is correct
38 Correct 213 ms 103076 KB Output is correct
39 Correct 237 ms 103432 KB Output is correct
40 Correct 206 ms 102768 KB Output is correct
41 Correct 128 ms 62732 KB Output is correct
42 Correct 127 ms 62692 KB Output is correct
43 Correct 167 ms 102272 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 1 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 1 ms 2636 KB Output is correct
48 Correct 1 ms 2636 KB Output is correct
49 Correct 4 ms 4684 KB Output is correct
50 Correct 5 ms 4684 KB Output is correct
51 Correct 8 ms 4684 KB Output is correct
52 Correct 7 ms 4684 KB Output is correct
53 Correct 113 ms 102272 KB Output is correct
54 Correct 223 ms 103164 KB Output is correct
55 Correct 231 ms 105800 KB Output is correct
56 Correct 190 ms 104644 KB Output is correct
57 Correct 339 ms 106808 KB Output is correct
58 Correct 118 ms 103160 KB Output is correct
59 Correct 180 ms 104072 KB Output is correct