結果
問題 | No.614 壊れたキャンパス |
ユーザー |
![]() |
提出日時 | 2017-12-14 01:07:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 245 ms / 2,000 ms |
コード長 | 2,020 bytes |
コンパイル時間 | 1,087 ms |
コンパイル使用メモリ | 86,896 KB |
実行使用メモリ | 11,828 KB |
最終ジャッジ日時 | 2024-12-14 10:43:36 |
合計ジャッジ時間 | 4,579 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;struct P {bool operator<(const P& p) const {return a < p.a;}int a, b, c;int64_t d;};struct Q {bool operator<(const Q& q) const {return c < q.c;}int c, i;int64_t d;};int main() {int n, m, k, s, t;cin >> n >> m >> k >> s >> t;vector<P> p(m + 2);p[0] = { 0, 0, s, 0 };p[m + 1] = { n, t, 0, 0 };for (int i = 1; i <= m; i++) {cin >> p[i].a >> p[i].b >> p[i].c;}sort(p.begin(), p.end());vector<int> l(n + 2);for (int i = m + 1; i >= 0; i--) {l[p[i].a] = i;}l[n + 1] = m + 2;for (int i = 1; i < n; i++) {if (l[i] == 0) {cout << -1 << endl;quick_exit(0);}}vector<Q> q(m + 2);for (int a = 0; a < n; a++) {int h = 0;for (int i = l[a]; i < l[a + 1]; i++) {q[h++] = { p[i].c, -1, p[i].d };}for (int i = l[a + 1]; i < l[a + 2]; i++) {q[h++] = { p[i].b, i, -1 };}sort(q.begin(), q.begin() + (l[a + 2] - l[a]));int64_t d = (int64_t)1 << 60;for (int i = 0; i < h; i++) {if (i != 0) d += q[i].c - q[i - 1].c;if (q[i].i < 0) {d = min(d, q[i].d);} else {if (q[i].d < 0 || q[i].d > d) q[i].d = d;}}d = (int64_t)1 << 60;for (int i = h - 1; i >= 0; i--) {if (i != h - 1) d += q[i + 1].c - q[i].c;if (q[i].i < 0) {d = min(d, q[i].d);} else {if (q[i].d < 0 || q[i].d > d) q[i].d = d;}}for (int i = 0; i < h; i++) {if (q[i].i >= 0) {p[q[i].i].d = q[i].d;}}}cout << p[m + 1].d << endl;return 0;}