結果
| 問題 |
No.614 壊れたキャンパス
|
| コンテスト | |
| ユーザー |
Kutimoti_T
|
| 提出日時 | 2018-06-24 13:57:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,953 bytes |
| コンパイル時間 | 1,805 ms |
| コンパイル使用メモリ | 183,724 KB |
| 実行使用メモリ | 38,336 KB |
| 最終ジャッジ日時 | 2024-06-30 22:28:02 |
| 合計ジャッジ時間 | 9,979 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 RE * 11 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
int N,M,K,S,T;
vector<int> A,B,C;
vector<map<i64,i64>> dp;
int main(){
cin >> N >> M >> K >> S >> T;
A.resize(N);
B.resize(N);
C.resize(N);
vector<vector<pair<i64,i64>>> vec(N);
dp.resize(N);
rep(i,0,M - 1){
cin >> C[i] >> A[i] >> B[i];
C[i]--;
vec[C[i]].push_back({B[i],A[i]});
}
vec[N - 1].push_back({-1,T});
rep(i,0,N - 2){
sort(vec[i].begin(),vec[i].end());
}
for(auto p : vec[0]){
dp[0][p.second] = abs(S - p.second);
}
rep(c,1,N - 1){
auto & before = vec[c - 1];
auto & next = vec[c];
vector<i64> up_min;
vector<i64> bot_min;
for(auto p : before){
i64 a = p.second;
i64 b = p.first;
if(up_min.empty()){
up_min.push_back(dp[c - 1][a] - b);
}
else{
up_min.push_back(min(up_min.back(),dp[c - 1][a] - b));
}
}
reverse(before.begin(),before.end());
for(auto p : before){
i64 a = p.second;
i64 b = p.first;
if(bot_min.empty()){
bot_min.push_back(dp[c - 1][a] + b);
}
else{
bot_min.push_back(min(bot_min.back(),dp[c - 1][a] + b));
}
}
reverse(before.begin(),before.end());
int cnt = 0;
if(before.empty()){
cout << -1 << endl;
return 0;
}
for(auto p : next){
i64 s = p.second;
while(cnt < before.size() && s > before[cnt].first){
cnt++;
}
i64 MIN;
if(cnt == 0){
MIN = bot_min[bot_min.size() - cnt - 1] - s;
}
else if(cnt == bot_min.size()){
MIN = up_min[cnt - 1] + s;
}
else{
MIN = min(bot_min[bot_min.size() - cnt - 1] - s, up_min[cnt - 1] + s);
}
dp[c][s] = MIN;
}
}
i64 ans = 1e18;
for(auto p : dp[N - 1]){
ans = min(ans , p.second + abs(T - p.first));
}
cout << ans << endl;
}
Kutimoti_T