結果
| 問題 | No.614 壊れたキャンパス |
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2017-12-13 20:58:52 |
| 言語 | C++11(廃止可能性あり) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,486 bytes |
| 記録 | |
| コンパイル時間 | 733 ms |
| コンパイル使用メモリ | 78,416 KB |
| 実行使用メモリ | 93,984 KB |
| 最終ジャッジ日時 | 2024-12-14 10:23:47 |
| 合計ジャッジ時間 | 8,597 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 14 |
ソースコード
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using P = pair<int, int>; // (棟, 階)
const int maxn = 300000;
const int64 inf = (1LL << 60);
map<int, int64> table[maxn];
map<int, vector<int>> G[maxn];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int64 N, M, K, S, T;
cin >> N >> M >> K >> S >> T;
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
a--;
G[a][b].push_back(c);
table[a][b] = inf;
table[a + 1][c] = inf;
}
for (auto& mp : table[N - 1]) mp.second = abs(T - mp.first);
for (int i = 0; i < N - 1; i++) {
for (auto& p : table[i]) {
for (int to : G[i][p.first]) {
p.second = min(p.second, table[i + 1][to]);
}
}
int64 val = inf;
for (auto it = table[i].begin(); it != table[i].end(); it++) {
it->second = min(it->second, val + it->first);
val = min(val, it->second - it->first);
}
val = inf;
for (auto it = table[i].rbegin(); it != table[i].rend(); it++) {
it->second = min(it->second, val - it->first);
val = min(val, it->second + it->first);
}
}
int64 ans = inf;
for (auto& mp : table[0]) ans = min(ans, mp.second + abs(S - mp.first));
if (ans >= inf / 2) cout << -1 << endl;
else cout << ans << endl;
return 0;
}
ふーらくたる