Submission #848326

#TimeUsernameProblemLanguageResultExecution timeMemory
848326KN200711Voting Cities (NOI22_votingcity)C++14
100 / 100
171 ms10696 KiB
# 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[b].push_back(make_pair(a, 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; // cout<<"a : "<<a<<" "<<c<<endl; 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<32;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 (stderr)

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:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d", &S);
      |   ~~~~~^~~~~~~~~~
Main.cpp:66:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   for(int i=0;i<5;i++) scanf("%lld", &P[i]);
      |                        ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...