結果

問題 No.2764 Warp Drive Spacecraft
ユーザー 沙耶花沙耶花
提出日時 2024-05-17 22:21:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,712 bytes
コンパイル時間 5,034 ms
コンパイル使用メモリ 281,516 KB
実行使用メモリ 24,336 KB
最終ジャッジ日時 2024-05-17 22:21:57
合計ジャッジ時間 11,388 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 298 ms
24,336 KB
testcase_17 AC 277 ms
24,336 KB
testcase_18 AC 269 ms
24,212 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 222 ms
15,316 KB
testcase_34 AC 231 ms
15,448 KB
testcase_35 AC 227 ms
15,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:9: warning: #pragma once in main file
   20 | #pragma once
      |         ^~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
/**
 * Author: Simon Lindholm
 * Date: 2017-04-20
 * License: CC0
 * Source: own work
 * Description: Container where you can add lines of the form kx+m, and query maximum values at points x.
 *  Useful for dynamic programming (``convex hull trick'').
 * Time: O(\log N)
 * Status: stress-tested
 */
#pragma once
using ll =long long;
struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	static const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) return x->p = inf, 0;
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};

vector<long long> get_distance(vector<vector<pair<int,long long>>> &E,int s){
	int N = E.size();
	vector<long long> dist(N,Inf64);
	dist[s] = 0;
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> pq;
	pq.push({0,s});
	while(!pq.empty()){
		auto [d,u] = pq.top();
		pq.pop();
		if(dist[u] !=d )continue;
		for(auto [v,w]:E[u]){
			if(dist[v] > dist[u] + w){
				dist[v] = dist[u] + w;
				pq.push({dist[v],v});
			}
		}
	}
	return dist;
}

int main(){
	int N,M;
	cin>>N>>M;
	vector<long long> w(N);
	rep(i,N)cin>>w[i];
	
	vector<vector<pair<int,long long>>> E(N);
	rep(i,M){
		int u,v,w;
		cin>>u>>v>>w;
		u--,v--;
		E[u].push_back({v,w});
		E[v].push_back({u,w});
	}
	
	auto x = get_distance(E,0),y = get_distance(E,N-1);
	long long ans = x[N-1];
	
	vector<long long> xs;
	rep(i,N){
		if(y[i]!=Inf64)xs.push_back(y[i]);
	}
	sort(xs.begin(),xs.end());
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	LineContainer cht;
	rep(i,N){
		if(x[i]==Inf64)continue;
		cht.add(-w[i],-x[i]);
		//cout<<w[i]<<endl;
	}
	rep(i,N){
		if(y[i]==Inf64)continue;
		//cout<<i<<' '<<cht.query(w[i])<<endl;
		ans = min(ans,-cht.query(w[i]) + y[i]);
		//cout<<w[i]<<endl;
	}
	cout<<ans<<endl;
	
	return 0;
}
0