結果
問題 | No.614 壊れたキャンパス |
ユーザー | ferin |
提出日時 | 2017-12-14 21:11:39 |
言語 | C++11 (gcc 11.4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,096 bytes |
コンパイル時間 | 1,999 ms |
コンパイル使用メモリ | 186,572 KB |
実行使用メモリ | 131,584 KB |
最終ジャッジ日時 | 2024-05-08 10:16:12 |
合計ジャッジ時間 | 19,372 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
8,032 KB |
testcase_01 | AC | 4 ms
7,980 KB |
testcase_02 | AC | 5 ms
8,044 KB |
testcase_03 | AC | 4 ms
8,092 KB |
testcase_04 | AC | 4 ms
8,164 KB |
testcase_05 | AC | 5 ms
8,156 KB |
testcase_06 | AC | 5 ms
8,048 KB |
testcase_07 | AC | 5 ms
8,176 KB |
testcase_08 | AC | 1,542 ms
129,984 KB |
testcase_09 | AC | 1,815 ms
129,116 KB |
testcase_10 | RE | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 1,675 ms
131,584 KB |
testcase_14 | AC | 1,594 ms
131,124 KB |
testcase_15 | RE | - |
testcase_16 | AC | 1,452 ms
128,012 KB |
testcase_17 | WA | - |
testcase_18 | AC | 1,114 ms
120,740 KB |
testcase_19 | AC | 1,202 ms
116,744 KB |
ソースコード
#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; // #define int ll typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define IN(a, b, x) (a<=x&&x<b) #define MP make_pair #define PB push_back #ifdef int const ll INF = (1LL<<60); #else const int INF = (1LL<<30); #endif const double PI = 3.14159265359; const double EPS = 1e-12; const int MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.first<<','<<a.second<<')'; return out; } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; map<PII, VVI> g; VI x[200010]; map<PII, int> d; signed main(void) { int n, m, k, s, t; cin >> n >> m >> k >> s >> t; s--, t--; REP(i, m) { int a, b, c; cin >> a >> b >> c; a--, b--, c--; // building, floor, cost g[{a, b}].PB({a+1, c, 0}); x[a].PB(b); x[a+1].PB(c); } x[0].PB(s); x[n-1].PB(t); REP(i, n) { sort(ALL(x[i])); REP(j, x[i].size()-1) { // x[j] -> x[j+1] g[{i, x[i][j]}].PB({(int)i, x[i][j+1], x[i][j+1]-x[i][j]}); g[{i, x[i][j+1]}].PB({(int)i, x[i][j], x[i][j+1]-x[i][j]}); d[{i, x[i][j]}] = INF; } d[{i, x[i].back()}] = INF; } priority_queue<VI, VVI, greater<VI>> que; que.push({0, 0, s}); d[{0, s}] = 0; while(que.size()) { VI v = que.top(); que.pop(); int cost = v[0], build = v[1], flr = v[2]; if(cost > d[{build, flr}]) continue; for(auto i: g[{build, flr}]) { if(d[{i[0], i[1]}] > d[{build, flr}] + i[2]) { d[{i[0], i[1]}] = d[{build, flr}] + i[2]; que.push({d[{i[0], i[1]}], i[0], i[1]}); } } } if(d[{n-1, t}] == INF) cout << -1 << endl; else cout << d[{n-1, t}] << endl; return 0; }