結果

問題 No.614 壊れたキャンパス
ユーザー koyoprokoyopro
提出日時 2020-02-05 02:07:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,316 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 176,632 KB
実行使用メモリ 167,520 KB
最終ジャッジ日時 2023-10-21 06:47:29
合計ジャッジ時間 6,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
75,320 KB
testcase_01 AC 30 ms
75,320 KB
testcase_02 AC 30 ms
75,320 KB
testcase_03 AC 30 ms
75,320 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 30 ms
75,320 KB
testcase_07 AC 31 ms
75,320 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 923450
#endif

int MAX = LONG_LONG_MAX/2;
int N,M,K,S,T;
map<int, int> MAP[SIZE];

struct Edge {
    int src, to, w;
    Edge(int u, int v, int w): src(u), to(v), w(w) {};
};

vector< vector<Edge> > E(SIZE);

void add_edge(int u, int v, int w) {
    E[u].push_back(*new Edge(u,v,w));
    E[v].push_back(*new Edge(v,u,w));
}

int C[SIZE];

void solve() {
    cin>>N>>M>>K>>S>>T;
    int a,b,c;
    int id = 1;
    REP(i,M) {
        cin>>a>>b>>c;
        a--;
        MAP[a][b] = id++;
        MAP[a+1][c] = id++;
        E[MAP[a][b]].push_back(*new Edge(MAP[a][b],MAP[a+1][c],0));
    }
    if (!MAP[0][S]) MAP[0][S] = id++;
    if (!MAP[N-1][T]) MAP[N-1][T] = id++;
    
    REP(i,N) {
        int prev = -1;
        for (auto p:MAP[i]) {
            int floor = p.first;
            int id = p.second;
            if (prev>-1) {
                int diff = floor - prev;
                int previd = MAP[i][prev];
                add_edge(previd, id, diff);
            }
            prev = floor;
        }
    }
    REP(i,SIZE) C[i]=MAX;
    
    queue<int> que;
    que.push(MAP[0][S]);
    C[MAP[0][S]] = 0;
    while(!que.empty()) {
        int id = que.front();
        que.pop();
        for (auto e:E[id]) {
            int cost = C[id] + e.w;
            if (cost < C[e.to]) {
                C[e.to] = cost;
                que.push(e.to);
            }
        }
    }
    
    int ans = C[MAP[N-1][T]];
    cout << (ans==MAX ? -1 : ans) << endl;
}
0