結果
問題 |
No.614 壊れたキャンパス
|
ユーザー |
|
提出日時 | 2017-12-14 02:29:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,113 bytes |
コンパイル時間 | 1,628 ms |
コンパイル使用メモリ | 127,208 KB |
実行使用メモリ | 301,472 KB |
最終ジャッジ日時 | 2024-12-14 10:51:26 |
合計ジャッジ時間 | 12,063 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 12 RE * 6 TLE * 1 |
ソースコード
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "iomanip" #include "cmath" using namespace std; const long long int MOD = 1000000007; long long int N, M, K, H, W, L, R; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M >> K >> L >> R; vector<pair<long long int, long long int>>edge; vector<map<int, int>>m(N + 1); map<long long int, long long int>dis; for (int i = 0; i < M; i++) { long long int a, b, c; cin >> a >> b >> c; m[a][b]++; m[a + 1][c]++; edge.push_back({ a*MOD + b,(a + 1)*MOD + c }); edge.push_back({ (a + 1)*MOD + c,a*MOD + b }); } sort(edge.begin(), edge.end()); m[1][L]++; m[N][R]++; for (int i = 1; i <= N; i++) { for (auto j : m[i]) { dis[i*MOD + j.second] = LLONG_MAX; } } dis[MOD + L] = 0; priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int>>, greater<pair<long long int, long long int>>>PQ; PQ.push({ 0,MOD + L }); while (!PQ.empty()) { auto box = PQ.top(); PQ.pop(); int cw = box.second / MOD; int ch = box.second %MOD; int cc = box.first; auto it = m[cw].find(ch); if (it != m[cw].begin()) { it--; int nh = (*it).second; if (dis[cw*MOD + nh] > cc + ch - nh) { dis[cw*MOD + nh] = cc + ch - nh; PQ.push({ dis[cw*MOD + nh],cw*MOD + nh }); } it++; } it++; if (it != m[cw].end()) { int nh = (*it).second; if (dis[cw*MOD + nh] > cc + nh - ch) { dis[cw*MOD + nh] = cc + nh - ch; PQ.push({ dis[cw*MOD + nh],cw*MOD + nh }); } } auto itb = lower_bound(edge.begin(), edge.end(), make_pair(cw*MOD + ch, (long long int)0)); auto ite = lower_bound(edge.begin(), edge.end(), make_pair((cw + 1)*MOD + ch, (long long int)0)); for (; itb != ite; ++itb) { int n = (*itb).second; if (dis[n] > cc) { dis[n] = cc; PQ.push({ cc,n }); } } } if (dis[N*MOD + R] == LLONG_MAX) { cout << -1 << endl; return 0; } cout << dis[N*MOD + R] << endl; return 0; }