Submission #937223

# Submission time Handle Problem Language Result Execution time Memory
937223 2024-03-03T16:23:53 Z Litusiano Voting Cities (NOI22_votingcity) C++17
100 / 100
259 ms 3616 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18;
vector<vector<pair<int,int>>> G;
vector<vector<int>> dp;
vector<int> ct;

void dijkstra(int s){	
	priority_queue<tuple<int,int,int>>pq;
	pq.push({0,s,0}); // cost node msk
	while(!pq.empty()){
		int w,u,msk; tie(w,u,msk) = pq.top(); pq.pop();
		if(w > dp[u][msk]) continue;
		for(auto p : G[u]){
			int v = p.first; int cost = p.second;
			for(int i = 0; i<6; i++){
				if(i > 0 && msk & (1<<(i-1)) || ct[i] == -1) {
					continue;
				}
				int t = cost-(i*(cost/10)) + ct[i];
				if(t > cost) continue;
				if(!i){
					if(dp[v][msk] > dp[u][msk] + t){
						dp[v][msk] = dp[u][msk]+t;
						pq.push({-dp[v][msk],v,msk});
					}
				}
				else{
					if(dp[v][msk ^ (1<<(i-1))] > dp[u][msk] + t){
						dp[v][msk ^ (1<<(i-1))] = dp[u][msk]+t;
						pq.push({-dp[u][msk]-t, v,(msk ^ (1<<(i-1))) }); 
					}
				}
			}
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,e,k; cin>>n>>e>>k;
	vector<int> good;
	for(int i = 0; i<k; i++){
		int x; cin>>x;
		good.push_back(x);
	}
	G.resize(n+1);
	for(int i = 0; i<e; i++){
		int u,v,w; cin>>u>>v>>w;
		G[u].push_back({v,w});
	}
	int q; cin>>q;
	while(q--){
		ct.assign(6,0);
		dp.assign(n+1, vector<int>(32, inf));
		int s; cin>>s;
		// cerr<<"S: "<<s<<endl;
		for(int i = 1; i<=5; i++) cin>>ct[i];
		dp[s][0] = 0;
		dijkstra(s);
		int ans = inf;
		for(int i = 0; i<k; i++){
			// cerr<<good[i]<<endl;
			for(int j = 0; j<32; j++){
				ans = min(ans,dp[good[i]][j]);
			}
		}
		if(ans == inf) ans = -1;
		cout<<ans<<"\n";
	}
}

Compilation message

Main.cpp: In function 'void dijkstra(long long int)':
Main.cpp:20:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   20 |     if(i > 0 && msk & (1<<(i-1)) || ct[i] == -1) {
      |        ~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 55 ms 2140 KB Output is correct
7 Correct 26 ms 2140 KB Output is correct
8 Correct 83 ms 2324 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 55 ms 2140 KB Output is correct
7 Correct 26 ms 2140 KB Output is correct
8 Correct 83 ms 2324 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 59 ms 2140 KB Output is correct
12 Correct 22 ms 2136 KB Output is correct
13 Correct 77 ms 2140 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 2396 KB Output is correct
7 Correct 2 ms 2140 KB Output is correct
8 Correct 5 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 55 ms 2140 KB Output is correct
7 Correct 26 ms 2140 KB Output is correct
8 Correct 83 ms 2324 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 7 ms 2396 KB Output is correct
12 Correct 2 ms 2140 KB Output is correct
13 Correct 5 ms 2272 KB Output is correct
14 Correct 259 ms 3516 KB Output is correct
15 Correct 67 ms 2264 KB Output is correct
16 Correct 188 ms 3112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2140 KB Output is correct
2 Correct 62 ms 2136 KB Output is correct
3 Correct 24 ms 2140 KB Output is correct
4 Correct 92 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 348 KB Output is correct
2 Correct 12 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 348 KB Output is correct
5 Correct 12 ms 584 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 21 ms 604 KB Output is correct
8 Correct 16 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2140 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
3 Correct 4 ms 2140 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 55 ms 2140 KB Output is correct
7 Correct 26 ms 2140 KB Output is correct
8 Correct 83 ms 2324 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 59 ms 2140 KB Output is correct
12 Correct 22 ms 2136 KB Output is correct
13 Correct 77 ms 2140 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 7 ms 2396 KB Output is correct
17 Correct 2 ms 2140 KB Output is correct
18 Correct 5 ms 2272 KB Output is correct
19 Correct 259 ms 3516 KB Output is correct
20 Correct 67 ms 2264 KB Output is correct
21 Correct 188 ms 3112 KB Output is correct
22 Correct 67 ms 2140 KB Output is correct
23 Correct 62 ms 2136 KB Output is correct
24 Correct 24 ms 2140 KB Output is correct
25 Correct 92 ms 2396 KB Output is correct
26 Correct 22 ms 348 KB Output is correct
27 Correct 12 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 13 ms 348 KB Output is correct
30 Correct 12 ms 584 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 21 ms 604 KB Output is correct
33 Correct 16 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 218 ms 3364 KB Output is correct
38 Correct 147 ms 2804 KB Output is correct
39 Correct 255 ms 3412 KB Output is correct
40 Correct 6 ms 1884 KB Output is correct
41 Correct 13 ms 2100 KB Output is correct
42 Correct 205 ms 3548 KB Output is correct
43 Correct 237 ms 3616 KB Output is correct
44 Correct 167 ms 2888 KB Output is correct
45 Correct 41 ms 2136 KB Output is correct