結果

問題 No.614 壊れたキャンパス
ユーザー tsutajtsutaj
提出日時 2017-12-14 00:36:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,176 bytes
コンパイル時間 1,780 ms
コンパイル使用メモリ 124,352 KB
実行使用メモリ 27,040 KB
最終ジャッジ日時 2024-05-08 08:05:34
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,824 KB
testcase_01 AC 6 ms
8,176 KB
testcase_02 AC 4 ms
8,192 KB
testcase_03 WA -
testcase_04 AC 6 ms
8,256 KB
testcase_05 AC 5 ms
8,192 KB
testcase_06 AC 6 ms
8,136 KB
testcase_07 WA -
testcase_08 TLE -
testcase_09 AC 746 ms
27,040 KB
testcase_10 AC 299 ms
13,360 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

vector<pii> edges[200010];
map< int, map<int, int> > rec;

signed main() {
    int N, M, K, S, T; cin >> N >> M >> K >> S >> T;
    rep(i,0,M) {
        int a, b, c; cin >> a >> b >> c;
        edges[a].push_back(make_pair(b, c));
    }

    queue<pii> que;
    que.push(make_pair(1, S));
    while(!que.empty()) {
        pii cur = que.front(); que.pop();
        int idx = cur.first, flr = cur.second;

        for(auto e : edges[idx]) {
            int cur_flr = e.first, nxt_flr = e.second;
            int cost = abs(flr - cur_flr);
            // printf("cur_flr = %lld, nxt_flr = %lld, cost = %lld\n", cur_flr, nxt_flr, cost);
            if(!rec[idx+1].count(nxt_flr) || rec[idx+1][nxt_flr] > rec[idx][flr] + cost) {
                rec[idx+1][nxt_flr] = rec[idx][flr] + cost;
                que.push(make_pair(idx+1, nxt_flr));
            }
        }
    }

    int ans = INF;
    for(auto x : rec[N]) {
        int flr = x.first, cost = x.second;
        // printf("flr = %lld, cost = %lld\n", flr, cost);
        chmin(ans, cost + abs(flr - T));
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}
0