結果
問題 | No.2764 Warp Drive Spacecraft |
ユーザー |
![]() |
提出日時 | 2024-05-20 02:24:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,975 bytes |
コンパイル時間 | 4,645 ms |
コンパイル使用メモリ | 274,100 KB |
最終ジャッジ日時 | 2025-02-21 16:14:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 19 WA * 16 |
ソースコード
#include <bits/stdc++.h>#include <cassert>#include <atcoder/all>using namespace std;using namespace atcoder;using ll = long long;using mint = modint998244353;//using mint = modint1000000007;#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define repu(i, s, t) for (int i = (int)(s); i < (int)(t); i++)#define repd(i, s, t) for (int i = (int)(s)-1; i >= (int)(t); i--)#define all(v) v.begin(), v.end()template<typename T> bool chmax(T &a, const T b) { if(a >= b) return false; a = b; return true; }template<typename T> bool chmin(T &a, const T b) { if(a <= b) return false; a = b; return true; }template<typename T> istream& operator>>(istream &in, vector<T> &a) { for(T &x: a) in >> x; return in; }template<typename T> ostream& operator<<(ostream &out, const vector<T> &a) { for(const T &x: a) out << x << ' '; return out; }const int di[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};const int dj[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};using COST = ll;const COST Z = 0;const COST E = 1;const COST INF = 1e18;struct DIJ {struct EDGE{int to; COST cost;};using EList = vector<EDGE>;using GRAPH = vector<EList>;using pci = pair<COST, int>;int n;GRAPH g;vector<vector<COST>> dist;DIJ(int n_): n(n_), g(n_), dist(n_) {}void add_edge(int a, int b, COST c = E) {g[a].push_back(EDGE{b, c});}vector<COST>& operator[](int i) {if(!dist[i].size()) solve(i);return dist[i];}void solve(int s) {dist[s].resize(n, INF);priority_queue<pci, vector<pci>, greater<pci>> wait;dist[s][s] = Z;wait.emplace(Z, s);while(!wait.empty()) {int pos; COST cost;tie(cost, pos) = wait.top(); wait.pop();if(dist[s][pos] < cost) continue;for(auto ed : g[pos]) {COST tmp = cost + ed.cost;if(dist[s][ed.to] <= tmp) continue;dist[s][ed.to] = tmp;wait.emplace(tmp, ed.to);}}}};int main() {int n, m;cin >> n >> m;vector<int> w(n);cin >> w;DIJ g(n);rep(i, m) {int u, v; ll t;cin >> u >> v >> t;u--; v--;g.add_edge(u, v, t);g.add_edge(v, u, t);}vector<int> ord(n);iota(all(ord), 0);sort(all(ord), [&](int l, int r) { return g[0][l] < g[0][r]; });map<ll, int> skip;skip[0] = 0;int pre = 0, ls = 0;rep(i, n) {if(w[ord[i]] >= w[ord[pre]]) continue;int tmp = w[ord[pre]] - w[ord[i]];ll bord = (g[0][ord[i]] - g[0][ord[pre]] + tmp - 1) / tmp;if(bord >= ls) {skip[bord] = i;pre = i;ls = bord;}}ll ans = g[0][n-1];rep(i, n) {int p = (*--skip.upper_bound(w[i])).second;chmin(ans, g[0][ord[p]] + g[n-1][i] + ll(w[ord[p]]) * w[i]);}cout << ans << endl;return 0;}