제출 #1272417

#제출 시각아이디문제언어결과실행 시간메모리
1272417huhuhuhuhuVoting Cities (NOI22_votingcity)C++20
30 / 100
9 ms1092 KiB
#include <bits/stdc++.h> #include <queue> using namespace std; long long n, e, k; vector<pair<long long, long long>> rel[5005]; pair<long long, long long> par[5005]; long long dist[5005]; bool isCity[5005]; vector<long long> cities; int main() { cin >> n >> e >> k; for (int i = 0; i <= n; i++) { par[i] = {-1, INFINITY}; dist[i] = -1; } for (int i = 0; i < k; i++) { long long c; cin >> c; isCity[c] = true; cities.push_back(c); } for (int i = 0; i < e; i++) { long long start, end, price; cin >> start >> end >> price; rel[end].push_back({start, price}); } priority_queue<array<long long, 4>, vector<array<long long, 4>>, greater<array<long long, 4>>> pq; // totalPrice, current, last, lastPrice for (auto &x : cities) { pq.push({0, x, -1, 0}); } while (!pq.empty()) { auto [price, pos, parent, lastPrice] = pq.top(); pq.pop(); if (dist[pos] <= price && dist[pos] != -1) { continue; } dist[pos] = price; par[pos] = {parent, lastPrice}; for (auto &next : rel[pos]) { pq.push({price + next.second, next.first, pos, next.second}); } } long long questions = 0; cin >> questions; for (int i = 0; i < questions; i++) { long long pos; cin >> pos; vector<long long> item; for (int j = 0; j < 5; j++) { long long v = 0; cin >> v; item.push_back(v); } long long total = 0; priority_queue<long long> prices; bool city = false; while (pos != -1) { // cout << pos << endl; if (isCity[pos]){ city = true; break; } total += par[pos].second; prices.push(par[pos].second); pos = par[pos].first; } if (!city) { cout << -1 << endl; continue; } for (long long j = 4; j >= 0; j--) { if (item[j] == -1) { continue; } if (prices.empty()) { break; } long long newPrice = prices.top() * (10ll - j - 1) / 10ll + item[j]; // cout << newPrice << " " << prices.top() << endl; if (newPrice >= prices.top()) { continue; } total = total - prices.top() + newPrice; prices.pop(); } cout << total << 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...