結果
問題 | No.2764 Warp Drive Spacecraft |
ユーザー |
![]() |
提出日時 | 2025-01-13 23:31:28 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,179 bytes |
コンパイル時間 | 7,640 ms |
コンパイル使用メモリ | 315,824 KB |
実行使用メモリ | 26,076 KB |
最終ジャッジ日時 | 2025-01-13 23:31:52 |
合計ジャッジ時間 | 17,995 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 TLE * 1 |
ソースコード
#ifdef t9unkubj#include"debug.cpp"//#include"template_no_debug.h"#else#define dbg(...) 199958#endif#undef _GLIBCXX_DEBUG#pragma GCC optimize("O3")using namespace std;#include<bits/stdc++.h>using ll=long long;using ull=unsigned long long;template<class T>using vc=vector<T>;template<class T>using vvc=vc<vc<T>>;#define rep(i,n) for(ll i=0;i<(ll)(n);i++)#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)#define drep(i,n) for(ll i=((n)-1);i>=0;i--)#define all(x) x.begin(),x.end()#define rall(x) x.rbegin(),x.rend()template<class T,class F>bool chmin(T &x, F y){if(x>y){x=y;return true;}return false;}template<class T, class F>bool chmax(T &x, F y){if(x<y){x=y;return true;}return false;}double pass_time=0;template< typename T, bool isMin >struct ConvexHullTrickAddMonotone {#define F first#define S secondusing P = pair< T, T >;deque< P > H;ConvexHullTrickAddMonotone() = default;bool empty() const { return H.empty(); }void clear() { H.clear(); }inline int sgn(T x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); }using D = long double;inline bool check(const P &a, const P &b, const P &c) {if(b.S == a.S || c.S == b.S)return sgn(b.F - a.F) * sgn(c.S - b.S) >= sgn(c.F - b.F) * sgn(b.S - a.S);//return (b.F-a.F)*(c.S-b.S) >= (b.S-a.S)*(c.F-b.F);returnD(b.F - a.F) * sgn(c.S - b.S) / D(abs(b.S - a.S)) >=D(c.F - b.F) * sgn(b.S - a.S) / D(abs(c.S - b.S));}void add(T a, T b) {if(!isMin) a *= -1, b *= -1;P line(a, b);if(empty()) {H.emplace_front(line);return;}if(H.front().F <= a) {if(H.front().F == a) {if(H.front().S <= b) return;H.pop_front();}while(H.size() >= 2 && check(line, H.front(), H[1])) H.pop_front();H.emplace_front(line);} else {assert(a <= H.back().F);if(H.back().F == a) {if(H.back().S <= b) return;H.pop_back();}while(H.size() >= 2 && check(H[H.size() - 2], H.back(), line)) H.pop_back();H.emplace_back(line);}}inline T get_y(const P &a, const T &x) {return a.F * x + a.S;}T query(T x) {assert(!empty());int l = -1, r = H.size() - 1;while(l + 1 < r) {int m = (l + r) >> 1;if(get_y(H[m], x) >= get_y(H[m + 1], x)) l = m;else r = m;}if(isMin) return get_y(H[r], x);return -get_y(H[r], x);}T query_monotone_inc(T x) {assert(!empty());while(H.size() >= 2 && get_y(H.front(), x) >= get_y(H[1], x)) H.pop_front();if(isMin) return get_y(H.front(), x);return -get_y(H.front(), x);}T query_monotone_dec(T x) {assert(!empty());while(H.size() >= 2 && get_y(H.back(), x) >= get_y(H[H.size() - 2], x)) H.pop_back();if(isMin) return get_y(H.back(), x);return -get_y(H.back(), x);}#undef F#undef S};void solve(){int n,m;cin>>n>>m;vc<ll>w(n);rep(i,n)cin>>w[i];vvc<pair<ll,ll>>g(n);rep(i,m){ll a,b,t;cin>>a>>b>>t;g[--a].push_back({--b,t});g[b].push_back({a,t});}auto D=[&](int st){using S=pair<ll,ll>;vc<ll>md(n,1e18);md[st]=0;priority_queue<S,vc<S>,greater<>>que;que.push({0,st});while(que.size()){auto [p,q]=que.top();que.pop();for(auto&[to,w]:g[q]){if(chmin(md[to],md[q]+w))que.push({md[to],to});}}return md;};auto A1=D(0);auto A2=D(n-1);ConvexHullTrickAddMonotone<ll,1>cht;vc<int>idx(n);iota(all(idx),0);sort(all(idx),[&](int i,int j){return w[i]<w[j];});for(auto&i:idx){cht.add(w[i],A2[i]);}ll ans=2e18;rep(i,n){chmin(ans,A1[i]+cht.query(w[i]));}chmin(ans,A1[n-1]);cout<<ans<<"\n";}signed main(){cin.tie(0)->sync_with_stdio(0);pass_time=clock();int t=1;//cin>>t;while(t--)solve();pass_time=clock()-pass_time;dbg(pass_time/CLOCKS_PER_SEC);}