제출 #1238977

#제출 시각아이디문제언어결과실행 시간메모리
1238977cowwycowVoting Cities (NOI22_votingcity)C++20
25 / 100
1095 ms32952 KiB
#pragma GCC optimize("O3,unroll-loops") #include <bits/stdc++.h> using namespace std; #define name "aaaaaa" #define endl "\n" #define fi first #define se second using ll = long long; using db = double; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using ppii = pair<int, pii>; using vi = vector<int>; using vll = vector<ll>; using vd = vector<double>; using pdb = pair<db, db>; bool bit(int i, int j){ return i >> j & 1; } const int N = 5e3 + 5, M = (1 << 5) + 3, K = N * M; const ll inf = 1e18; vector<pll> e[K]; vector<int> voting; ll d[K]; vector<int> source; void dijkstra(){ for(int i = 0; i < K; i++){ d[i] = inf; } for(int i = 0; i < source.size(); i++){ d[source[i]] = 0; } priority_queue<pll, vector<pll>, greater<pll> > pq; for(int i = 0; i < source.size(); i++){ pq.push({0, source[i]}); } while(!pq.empty()){ ll distu = pq.top().first; int u = pq.top().second; pq.pop(); if(distu != d[u]){ continue; } for(auto [v, len] : e[u]){ if(d[u] + len < d[v]){ d[v] = d[u] + len; pq.push({d[v], v}); } } } } ll price[6]; void solve(){ int n, m, k; cin >> n >> m >> k; while(k--){ int x; cin >> x; voting.push_back(x); } int lim = 1 << 5; while(m--){ int u, v; ll w; cin >> u >> v >> w; for(int i = 0; i < lim; i++){ e[i * n + u].push_back({i * n + v, w}); for(int j = 1; j <= 5; j++){ if(bit(i, j - 1) == false){ int cur = i ^ (1 << (j - 1)); e[i * n + u].push_back({cur * n + v, w / 10 * (10 - j)}); } } } } int q; cin >> q; while(q--){ int start; cin >> start; for(int i = 1; i <= 5; i++){ cin >> price[i]; } source.clear(); source.push_back(start); dijkstra(); ll ans = inf; for(int i = 0; i < lim; i++){ bool possible = true; ll sump = 0; for(int j = 1; j <= 5; j++){ if(bit(i, j - 1)){ if(price[j] == -1) possible = false; else sump += price[j]; } } if(possible == true){ ll sus = inf; for(int j : voting){ sus = min(sus, d[i * n + j]); } ans = min(ans, sus + sump); } } cout << (ans >= inf ? -1 : ans) << endl; } } int main(){ if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } int test = 1; //cin >> test; while(test--){ solve(); } }

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

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