Submission #815982

#TimeUsernameProblemLanguageResultExecution timeMemory
815982zulsinar031Voting Cities (NOI22_votingcity)C++98
100 / 100
377 ms21780 KiB
//Singapore NOI 2022 - Voting Cities #include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define mp make_pair const int INF = 1e18+7; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, e, k; cin >> n >> e >> k; int t[k]; vector<vector<pair<int,int>>>edges(n+1); set<pair<int,pair<int,int>>>d; for(int i = 0; i < k; i++){ cin >> t[i]; d.insert(mp(0,mp(t[i],0))); } for(int i = 0; i < e; i++){ int u, v, w; cin >> u >> v >> w; //edges[u].push_back({v,w}); edges[v].push_back({u,w}); } int dp[n][1<<5]; bool vis[n][1<<5]; memset(dp,-1,sizeof(dp)); memset(vis,0,sizeof(vis)); while(d.size()) { int dist = (*d.begin()).fi; int nd = (*d.begin()).se.fi; int mask = (*d.begin()).se.se; d.erase(d.begin()); if(vis[nd][mask]) continue; dp[nd][mask] = dist; vis[nd][mask] = 1; for(pair<int,int> i : edges[nd]){ if(!vis[i.fi][mask]) d.insert(mp(dist+i.se,mp(i.fi, mask))); for(int j = 0; j < 5; j++){ if(!((1<<j) & mask)){ if(!vis[i.fi][mask | (1<<j)]) d.insert(mp(dist+i.se/10ll * (10ll-j-1ll), mp(i.fi, mask | (1<<j)))); } } } } int q; cin >> q; while(q--) { int p[6], s; cin >> s; for(int i = 0; i < 5; i++) cin >> p[i]; int ans = 1e18; for(int j = 0; j < 1 << 5; j++){ if(dp[s][j] != -1){ bool valid = 1; int cost = 0; for(int k = 0; k < 5; k++){ if((1<<k) & j){ if(p[k] == -1) valid = 0; else cost+=p[k]; } } if(valid) ans = min(ans,dp[s][j] + cost); } } if(ans == 1e18) cout << -1 << endl; else cout << ans << endl; } }
#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...