結果
問題 | No.2477 Drifting |
ユーザー | shobonvip |
提出日時 | 2023-09-18 21:03:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 2,896 bytes |
コンパイル時間 | 4,288 ms |
コンパイル使用メモリ | 291,544 KB |
実行使用メモリ | 40,948 KB |
最終ジャッジ日時 | 2024-07-05 10:20:54 |
合計ジャッジ時間 | 12,134 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 470 ms
40,704 KB |
testcase_01 | AC | 303 ms
30,848 KB |
testcase_02 | AC | 478 ms
40,832 KB |
testcase_03 | AC | 360 ms
28,032 KB |
testcase_04 | AC | 142 ms
19,584 KB |
testcase_05 | AC | 313 ms
26,112 KB |
testcase_06 | AC | 548 ms
40,832 KB |
testcase_07 | AC | 559 ms
40,948 KB |
testcase_08 | AC | 400 ms
33,988 KB |
testcase_09 | AC | 196 ms
23,680 KB |
testcase_10 | AC | 211 ms
26,112 KB |
testcase_11 | AC | 196 ms
22,272 KB |
testcase_12 | AC | 282 ms
29,312 KB |
testcase_13 | AC | 7 ms
11,264 KB |
testcase_14 | AC | 6 ms
11,264 KB |
testcase_15 | AC | 7 ms
11,392 KB |
testcase_16 | AC | 187 ms
21,248 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } ll floor_sqrt(ll n){ ll ub = 3e9 + 30; ll lb = 0; while(ub - lb > 1){ ll t = (ub + lb) / 2; if (t * t <= n){ lb = t; }else{ ub = t; } } return lb; } //defmodfact const int COMinitMAX = 992844; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a<b || b<0) return mint(0); return fact[a]*factinv[b]*factinv[a-b]; } //-------- int main(){ int n, m; cin >> n >> m; vector ikeru(n, vector<pair<int,ll>>(0)); rep(i,0,m){ int u, v; ll w; cin >> u >> v >> w; u--; v--; ikeru[u].push_back(pair(v, w)); } int k; cin >> k; vector<int> a(k), b(k), c(k); map<pair<int,int>,int> mp; vector bs(n, vector<int>(0)); set<tuple<int,int,int>> dame; rep(i,0,k){ cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i]--; if (mp.find(pair(a[i], b[i])) == mp.end()){ mp[pair(a[i], b[i])] = (int)mp.size(); bs[b[i]].push_back(a[i]); } dame.insert(make_tuple(a[i], b[i], c[i])); } int l = mp.size(); vector<ll> d(n,1e18); vector<ll> dk(l,1e18); d[0] = 0; rep(i,0,n){ vector<pair<ll,int>> ds; ds.push_back(pair(d[i], -1)); map<int,vector<int>> am; rep(j,0,(int)bs[i].size()){ ds.push_back(pair(dk[mp[pair(bs[i][j], i)]], bs[i][j])); } sort(ds.begin(), ds.end()); for(auto[j,w]:ikeru[i]){ rep(x,0,(int)ds.size()){ if (ds[x].second == -1 || dame.find(make_tuple(ds[x].second, i, j)) == dame.end()){ if(mp.find(pair(i, j))==mp.end()){ chmin(d[j], w+ds[x].first); }else{ chmin(dk[mp[pair(i, j)]], w+ds[x].first); } break; } } } } if (d[n-1] == 1e18){ cout << -1 << '\n'; }else{ cout << d[n-1] << '\n'; } }