Submission #233487

# Submission time Handle Problem Language Result Execution time Memory
233487 2020-05-20T17:17:53 Z eohomegrownapps Toll (BOI17_toll) C++14
18 / 100
3000 ms 15096 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});
	}
	vector<int> from;
	vector<vector<int>> addat(n/k+1);
	vector<vector<vector<int>>> distfrom(2,vector<vector<int>>(n,vector<int>(k,INF)));
	vector<vector<pair<int,int>>> to(n);
	vector<int> ans(o,-1);
	for (int i = 0; i<o; i++){
		int a,b;
		cin>>a>>b;
		from.push_back(a);
		addat[a/k].push_back(a);
		to[b].push_back({a,i});
	}
	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][x%k]=0;
		}
		for (int j = 0; j<k; j++){
			if (i*k+j>=n){break;}
			for (int nf : from){
				distfrom[curr][nf][j]=INF;
				for (auto p : adjlist[i*k+j]){
					distfrom[curr][nf][j]=min(distfrom[curr][nf][j],distfrom[!curr][nf][p.first%k]+p.second);
				}
			}
			for (auto p : to[i*k+j]){
				if (distfrom[curr][p.first][j]!=INF){
					ans[p.second]=distfrom[curr][p.first][j];
				}
			}
		}
		curr=!curr;
	}
	for (int i = 0; i<o; i++){
		cout<<ans[i]<<'\n';
	}
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 13432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 13560 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 392 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 8 ms 1024 KB Output is correct
8 Correct 9 ms 1024 KB Output is correct
9 Correct 44 ms 13432 KB Output is correct
10 Correct 76 ms 14584 KB Output is correct
11 Correct 64 ms 13688 KB Output is correct
12 Correct 52 ms 12924 KB Output is correct
13 Correct 72 ms 11064 KB Output is correct
14 Correct 48 ms 9208 KB Output is correct
15 Correct 43 ms 8568 KB Output is correct
16 Correct 41 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 95 ms 13304 KB Output is correct
11 Correct 131 ms 13432 KB Output is correct
12 Correct 186 ms 14584 KB Output is correct
13 Correct 200 ms 15096 KB Output is correct
14 Correct 158 ms 13816 KB Output is correct
15 Correct 110 ms 8568 KB Output is correct
16 Correct 104 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 640 KB Output is correct
7 Correct 7 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 8 ms 640 KB Output is correct
10 Correct 95 ms 13304 KB Output is correct
11 Correct 131 ms 13432 KB Output is correct
12 Correct 186 ms 14584 KB Output is correct
13 Correct 200 ms 15096 KB Output is correct
14 Correct 158 ms 13816 KB Output is correct
15 Correct 110 ms 8568 KB Output is correct
16 Correct 104 ms 8568 KB Output is correct
17 Correct 2915 ms 13580 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 17 ms 768 KB Output is correct
25 Correct 28 ms 768 KB Output is correct
26 Correct 24 ms 760 KB Output is correct
27 Correct 2628 ms 13312 KB Output is correct
28 Execution timed out 3066 ms 14584 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 13432 KB Time limit exceeded
2 Halted 0 ms 0 KB -