Submission #233495

# Submission time Handle Problem Language Result Execution time Memory
233495 2020-05-20T17:51:02 Z eohomegrownapps Toll (BOI17_toll) C++14
56 / 100
3000 ms 8312 KB
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int,int>>> adjlist;

int INF = 1e9;

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int k,n,m,o;
	cin>>k>>n>>m>>o;
	adjlist.resize((n/k)*k+k);
	for (int i = 0; i<m; i++){
		int a,b,t;
		cin>>a>>b>>t;
		adjlist[b].push_back({a,t});
	}
	unordered_set<int> from;
	vector<vector<int>> addat(n/k+1);
	//vector<vector<vector<int>>> distfrom(2,vector<vector<int>>(n,vector<int>(k,INF)));
	int distfrom[2][6][50000];
	for (int i = 0; i<2; i++){
		for (int x = 0; x<k; x++){
			for (int j = 0; j<n; j++){
				distfrom[i][x][j]=INF;
			}
		}
	}
	vector<vector<pair<int,int>>> to(n);
	int fromcnt[50000]={0};
	int ans[10000];
	for (int i = 0; i<o; i++){
		int a,b;
		cin>>a>>b;
		ans[i]=-1;
		//from.push_back(a);
		addat[a/k].push_back(a);
		to[b].push_back({a,i});
		fromcnt[a]++;
	}
	//sort(from.begin(),from.end());
	//from.erase(unique(from.begin(),from.end()),from.end());
	bool curr = 0;
	for (int i = 1; i<=(n/k+1); i++){
		//cout<<i<<endl;
		for (int x : addat[i-1]){
			distfrom[!curr][x%k][x]=0;
			from.insert(x);
		}
		for (int j = 0; j<k; j++){
			int ikj = i*k+j;
			if (ikj>=n){break;}
			for (int nf : from){
				distfrom[curr][j][nf]=INF;
				for (auto p : adjlist[ikj]){
					distfrom[curr][j][nf]=min(distfrom[curr][j][nf],distfrom[!curr][p.first%k][nf]+p.second);
				}
			}
			for (auto p : to[ikj]){
				if (distfrom[curr][j][p.first]!=INF){
					ans[p.second]=distfrom[curr][j][p.first];
				}
				fromcnt[p.first]--;
				if (fromcnt[p.first]==0){
					from.erase(p.first);
				}
			}
		}
		curr=!curr;
	}
	for (int i = 0; i<o; i++){
		cout<<ans[i]<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1495 ms 7048 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 1480 ms 6988 KB Output is correct
9 Correct 1436 ms 6908 KB Output is correct
10 Correct 1239 ms 5420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 6264 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 8 ms 896 KB Output is correct
8 Correct 9 ms 1024 KB Output is correct
9 Correct 30 ms 6400 KB Output is correct
10 Correct 74 ms 7160 KB Output is correct
11 Correct 49 ms 6264 KB Output is correct
12 Correct 38 ms 6392 KB Output is correct
13 Correct 62 ms 6136 KB Output is correct
14 Correct 40 ms 4736 KB Output is correct
15 Correct 38 ms 4728 KB Output is correct
16 Correct 35 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 42 ms 6016 KB Output is correct
11 Correct 72 ms 5880 KB Output is correct
12 Correct 107 ms 7032 KB Output is correct
13 Correct 106 ms 7416 KB Output is correct
14 Correct 79 ms 6520 KB Output is correct
15 Correct 53 ms 4608 KB Output is correct
16 Correct 50 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 42 ms 6016 KB Output is correct
11 Correct 72 ms 5880 KB Output is correct
12 Correct 107 ms 7032 KB Output is correct
13 Correct 106 ms 7416 KB Output is correct
14 Correct 79 ms 6520 KB Output is correct
15 Correct 53 ms 4608 KB Output is correct
16 Correct 50 ms 4608 KB Output is correct
17 Correct 766 ms 6264 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 5 ms 512 KB Output is correct
21 Correct 5 ms 512 KB Output is correct
22 Correct 5 ms 640 KB Output is correct
23 Correct 9 ms 768 KB Output is correct
24 Correct 11 ms 768 KB Output is correct
25 Correct 17 ms 896 KB Output is correct
26 Correct 15 ms 768 KB Output is correct
27 Correct 475 ms 6392 KB Output is correct
28 Correct 1114 ms 7044 KB Output is correct
29 Correct 1223 ms 7428 KB Output is correct
30 Correct 937 ms 6652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1495 ms 7048 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 7 ms 768 KB Output is correct
6 Correct 7 ms 768 KB Output is correct
7 Correct 7 ms 768 KB Output is correct
8 Correct 1480 ms 6988 KB Output is correct
9 Correct 1436 ms 6908 KB Output is correct
10 Correct 1239 ms 5420 KB Output is correct
11 Correct 52 ms 6264 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 8 ms 896 KB Output is correct
18 Correct 9 ms 1024 KB Output is correct
19 Correct 30 ms 6400 KB Output is correct
20 Correct 74 ms 7160 KB Output is correct
21 Correct 49 ms 6264 KB Output is correct
22 Correct 38 ms 6392 KB Output is correct
23 Correct 62 ms 6136 KB Output is correct
24 Correct 40 ms 4736 KB Output is correct
25 Correct 38 ms 4728 KB Output is correct
26 Correct 35 ms 4736 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 5 ms 512 KB Output is correct
29 Correct 5 ms 512 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 640 KB Output is correct
33 Correct 6 ms 640 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 42 ms 6016 KB Output is correct
37 Correct 72 ms 5880 KB Output is correct
38 Correct 107 ms 7032 KB Output is correct
39 Correct 106 ms 7416 KB Output is correct
40 Correct 79 ms 6520 KB Output is correct
41 Correct 53 ms 4608 KB Output is correct
42 Correct 50 ms 4608 KB Output is correct
43 Correct 766 ms 6264 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 5 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 512 KB Output is correct
48 Correct 5 ms 640 KB Output is correct
49 Correct 9 ms 768 KB Output is correct
50 Correct 11 ms 768 KB Output is correct
51 Correct 17 ms 896 KB Output is correct
52 Correct 15 ms 768 KB Output is correct
53 Correct 475 ms 6392 KB Output is correct
54 Correct 1114 ms 7044 KB Output is correct
55 Correct 1223 ms 7428 KB Output is correct
56 Correct 937 ms 6652 KB Output is correct
57 Execution timed out 3044 ms 8312 KB Time limit exceeded
58 Halted 0 ms 0 KB -