結果
問題 | No.1449 新プロランド |
ユーザー |
|
提出日時 | 2021-07-11 02:23:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,902 bytes |
コンパイル時間 | 4,297 ms |
コンパイル使用メモリ | 187,272 KB |
最終ジャッジ日時 | 2025-01-23 00:33:41 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 1 |
ソースコード
#include <atcoder/all> #include <bitset> #include <fstream> #include <functional> #include <iostream> #include <iomanip> #include <limits> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef std::pair<int, int> pii; typedef std::pair<int, ll> pil; typedef std::pair<ll, int> pli; typedef std::pair<ll, ll> pll; typedef std::pair<int, ld> pid; typedef std::pair<int, std::string> pis; typedef std::pair<ll, std::string> pls; typedef std::vector<bool> vb; typedef std::vector<vb> vvb; typedef std::vector<int> vi; typedef std::vector<vi> vvi; typedef std::vector<vvi> vvvi; typedef std::vector<vvvi> vvvvi; typedef std::vector<ll> vl; typedef std::vector<vl> vvl; typedef std::vector<vvl> vvvl; typedef std::vector<vvvl> vvvvl; typedef std::vector<ld> vd; typedef std::vector<vd> vvd; typedef std::vector<std::string> vs; #define rep(i,n) for(auto i=0; i<n; ++i) #define repm(i,s,n) for(auto i=s; i<n; ++i) #define repd(i,n) for(auto i=n-1; i>=0; --i) #define repdm(i,e,n) for(auto i=n-1; i>=e; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() template <class T> inline bool chmax(T& a, T b, int eq = 0) { if (a < b || (a == b && eq)) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b, int eq = 0) { if (a > b || (a == b && eq)) { a = b; return 1; } return 0; } template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr istream& operator>>(istream& is, mint& x) noexcept {long long v = 0; std::cin >> v; x = v; return is;} template <class mint, internal::is_modint_t<mint>* = nullptr> constexpr ostream& operator<<(ostream& os, const mint& x) noexcept {os << x.val(); return os;} inline void _n() { std::cout << std::endl; } template <class T> inline void _(const T a) { std::cout << a; } template <class T> inline void _l(const T a) { _(a); _n(); } template <class T> inline void _s(const T a) { _(a); _(' '); } template <class T> inline void _v(const std::vector<T> v) { for(auto a : v) _(a); } template <class T> inline void _vl(const std::vector<T> v) { for(auto a : v) _l(a); } template <class T> inline void _vs(const std::vector<T> v) { for(auto a : v) _s(a); _n(); } template <class T> inline void _vvl(const std::vector<std::vector<T>> v) { for(auto a : v) { _v(a); _n(); } } template <class T> inline void _vvs(const std::vector<std::vector<T>> v) { for(auto a : v) { _vs(a); } } inline void ynl(const bool b) {_l(b ? "yes" : "no");} inline void yns(const bool b) {_l(b ? "Yes" : "No");} inline void ynu(const bool b) {_l(b ? "YES" : "NO");} constexpr int INF = numeric_limits<int>::max() >> 1; constexpr long long INF_LL = numeric_limits<long long>::max() >> 1LL; constexpr long long MOD1 = 1000000007; constexpr long long MOD9 = 998244353; using mint1 = atcoder::modint1000000007; using mint9 = atcoder::modint998244353; //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// void solve() { int N, M; cin >> N >> M; vi A(M+1), B(M+1), C(M+1); rep(i, M) {cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--;} A[M] = B[M] = C[M] = 0; vi T(N); rep(i, N) cin >> T[i]; vvi G(N, vi()); rep(i, M+1) { G[A[i]].push_back(i); G[B[i]].push_back(i); } struct edge {int idx, from, to; ll cost, power;}; auto compare = [&] (edge a, edge b) -> bool { if(a.cost != b.cost) return a.cost > b.cost; else return false; }; priority_queue<edge, vector<edge>, function<bool(edge, edge)>> que(compare); vvl dist(N, vl(1002, INF_LL)); dist[0][0] = 0; que.push({M, 0, 0, 0, 0}); while(!que.empty()) { edge qf = que.top(); que.pop(); int v = qf.to; int p = (int)min(qf.power, 1001ll); if(dist[v][p] < qf.cost) continue; for (int idx : G[v]) { int from = A[idx]; int to = B[idx]; if(from == to) continue; if(v == to) swap(from, to); ll next_power = min(qf.power + T[from], 1001ll); ll next_cost = dist[v][p] + T[from] + C[idx] / next_power; if(dist[to][next_power] <= next_cost) continue; dist[to][next_power] = next_cost; que.push({idx, from, to, next_cost, next_power}); } } ll ans = INF_LL; rep(i, 1001) chmin(ans, dist[N-1][i]); _l(ans); } //* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *// int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); std::cin.tie(0); std::cout.tie(0); std::ios::sync_with_stdio(false); solve(); return 0; }