Submission #848325

# Submission time Handle Problem Language Result Execution time Memory
848325 2023-09-12T06:27:32 Z KN200711 Voting Cities (NOI22_votingcity) C++14
0 / 100
4 ms 1884 KB
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;

int N, E, K;
vector<int> T;
vector< pair<int, ll> > edge[5001];

ll dp[32][5001];
bool vis[32][5001];

int main() {
	scanf("%d %d %d", &N, &E, &K);
	T.resize(K);
	for(int i=0;i<K;i++) {
		scanf("%d", &T[i]);
	}
	
	for(int i=0;i<E;i++) {
		int a, b;
		ll c;
		scanf("%d %d %lld", &a, &b, &c);
		edge[a].push_back(make_pair(b, c));
	}
	
	for(int i=0;i<32;i++) {
		for(int k=0;k<N;k++) dp[i][k] = -1;
	}
	
	priority_queue< pair<int, pair<ll, int> > > PQ;
	for(int i=0;i<K;i++) {
		PQ.push(make_pair(0, make_pair(0, T[i])));
	}
	
	while(!PQ.empty()) {
		int a, c;
		ll b;
		a = -PQ.top().fi;
		b = -PQ.top().se.fi;
		c = PQ.top().se.se;
		PQ.pop();
		
		if(dp[a][c] != -1) continue;
		dp[a][c] = b;
		
		for(auto p : edge[c]) {
		//	for(int k=0;k<5;k++) {
		//		if(!(a&(1 << k))) {
		//			if(dp[a^(1 << k)][c] == -1) PQ.push(make_pair(-(a ^ (1 << k)), make_pair(-b - (10 - k - 1) * p.se / 10, p.fi)));
		//		}
		//	}
			if(dp[a][p.fi] == -1) {
				PQ.push(make_pair(-a, make_pair(-b-p.se, p.fi)));
			}
		}
	}
	int Q;
	scanf("%d", &Q);
	while(Q--) {
		int S;
		ll P[5];
		scanf("%d", &S);
		for(int i=0;i<5;i++) scanf("%lld", &P[i]);
		
		ll as = 0ll, ans = 1e18;
		for(int i=0;i<1;i++) {
		//	cout<<"i : "<<i<<" "<<dp[i][S]<<endl;
			if(dp[i][S] == -1) continue;
			as = dp[i][S];
			for(int k=0;k<5;k++) {
				if(i&(1 << k)) {
					if(P[k] == -1) {
						as = 1e18;
						break;
					}
					else as += P[k];
				}
			}
			ans = min(ans, as);
		}
		if(ans >= 1e18) ans = -1;
		printf("%lld\n", ans);
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d %d %d", &N, &E, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d", &T[i]);
      |   ~~~~~^~~~~~~~~~~~~
Main.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%d %d %lld", &a, &b, &c);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:64:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   scanf("%d", &S);
      |   ~~~~~^~~~~~~~~~
Main.cpp:65:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   for(int i=0;i<5;i++) scanf("%lld", &P[i]);
      |                        ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1880 KB Output isn't correct
2 Halted 0 ms 0 KB -