제출 #1169794

#제출 시각아이디문제언어결과실행 시간메모리
1169794nathan4690Voting Cities (NOI22_votingcity)C++20
100 / 100
66 ms29692 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define f1(i,n) for(int i=1;i<=n;i++) #define __file_name "" #define pii pair<ll, int> using namespace std; const ll maxn=1e6+5, inf=1e18; int n, e, k, t[maxn]; ll d[5005][1 << 5]; vector<pair<int,int>> G[maxn]; priority_queue<pii, vector<pii>, greater<pii>> pq; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(__file_name ".inp", "r")){ freopen(__file_name ".inp", "r", stdin); freopen(__file_name ".out", "w", stdout); } // code here cin >> n >> e >> k; f1(i,k) cin >> t[i]; f1(i, e){ int u, v, w; cin >> u >> v >> w; // G[u].push_back({v, w}); G[v].push_back({u, w}); } for(int i=0;i<n;i++) for(int m=0;m<(1 << 5);m++) d[i][m] = inf; f1(i,k) { d[t[i]][0] = 0; pq.push({0ll, (t[i] << 5)}); } while(!pq.empty()){ ll dst = pq.top().first, node = pq.top().second; int u = node >> 5, mask = node & ((1 << 5) - 1); pq.pop(); if(dst != d[u][mask]) continue; for(pair<int,int> e: G[u]){ ll c = e.first, w = e.second; if(d[c][mask] > d[u][mask] + w){ d[c][mask] = d[u][mask] + w; pq.push({d[c][mask], (c << 5) + mask}); } for(int i=0;i<5;i++){ if(!(mask >> i & 1)){ int nxtm = mask | (1 << i); ll mx = d[u][mask] + w - (w / 10 * (i + 1)); if(d[c][nxtm] > mx){ d[c][nxtm] = mx; pq.push({d[c][nxtm], (c << 5) + nxtm}); } } } } } int q; cin >> q; while(q--){ int s; ll co[5]; cin >> s; for(int i=0;i<5;i++){ cin >> co[i]; if(co[i] == -1) co[i] = inf; } ll ans = inf; for(int mask=0;mask<(1 << 5);mask++){ ll cur = d[s][mask]; for(int i=0;i<5;i++){ if(mask >> i & 1) cur += co[i]; } ans = min(ans, cur); } cout << (ans == inf ? -1LL : ans) << '\n'; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen(__file_name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(__file_name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...