結果
問題 | No.2321 Continuous Flip |
ユーザー | suisen |
提出日時 | 2024-12-14 16:05:02 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,191 bytes |
コンパイル時間 | 1,196 ms |
コンパイル使用メモリ | 87,716 KB |
実行使用メモリ | 21,424 KB |
最終ジャッジ日時 | 2024-12-14 16:05:13 |
合計ジャッジ時間 | 10,222 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 9 WA * 21 |
ソースコード
#include <iostream>#include <numeric>#include <queue>#include <vector>template <typename T>using min_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T>>;int main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int n, m;long long c;std::cin >> n >> m >> c;std::vector<long long> a(n);for (auto& e : a) {std::cin >> e;}std::vector<std::vector<int>> rs(n + 1);for (int i = 0; i < m; ++i) {int l, r;std::cin >> l >> r;--l;rs[l].push_back(r);}long long s = std::accumulate(a.begin(), a.end(), 0LL);min_priority_queue<std::pair<long long, int>> pq;std::vector<long long> d(n + 1, 1LL << 60);pq.emplace(d[0] = 0, 0);while (pq.size()) {auto [du, u] = pq.top();pq.pop();if (du != d[u]) continue;auto update = [&](int v, long long cost) {if (d[v] > du + cost) pq.emplace(d[v] = du + cost, v);};if (u != 0) update(u - 1, a[u - 1]);if (u != n) update(u + 1, a[u]);for (int r : rs[u]) update(r, c);}std::cout << s - d[n] << std::endl;}