結果

問題 No.614 壊れたキャンパス
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-12-14 22:30:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,829 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 110,264 KB
実行使用メモリ 286,268 KB
最終ジャッジ日時 2024-05-08 10:22:43
合計ジャッジ時間 9,687 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
using i64 = long long;

constexpr i64 inf = 987654321987654321LL;
struct edge { int to, cost; };
int N, M, K, S, T;
vector<tuple<int, int, int>> ABC;

// x棟が開始する番号を返す
int myfind(int x) {
  if(x >= N-1) { return M; }
  int lo = -1, hi = M-1;
  while(hi - lo > 1) {
    int md = (lo + hi) / 2;
    int cand = get<0>(ABC[md]);
    if(x <= cand) {
      hi = md;
    } else {
      lo = md;
    }
  }
  return hi;
}

int main(void) {
  scanf("%d%d%d%d%d", &N, &M, &K, &S, &T);
  --S, --T;
  // G[i] := { (i棟の始点の階, i+1棟の終点の階)のリスト }
  vector<vector<pair<int, int>>> G(N);
//  vector<pair<int, int>> corr0(M), corr1(M); // corr0[i] := 渡り廊下始点の (棟, 階)
//                                             // corr1[i] := 渡り廊下終点の (棟, 階)
  vector<map<int, int>> corr0_rev(N);
  for(int i=0; i<M; ++i) {
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    --a, --b, --c;
    ABC.emplace_back(a, b, c);
    G[a].emplace_back(b, c);
    corr0_rev[a]  [b] = i;
  }
  sort(begin(ABC), end(ABC));
  vector<vector<edge>> H(M+2);
  for(int a=0; a<N-1; ++a) {
    int a0pos = myfind(a),
        a1pos = myfind(a+1),
        a2pos = myfind(a+2);
    if(a0pos == -1) { continue; }
    for(int p0=a0pos; p0<a1pos; ++p0) {
      int _, b, c; tie(_, b, c) = ABC[p0];
      int node0 = corr0_rev[a][b];
      for(int p1=a1pos; p1<a2pos; ++p1) {
        int _, x, y; tie(_, x, y) = ABC[p1];
        int node1 = corr0_rev[a+1][x];
        H[node0].push_back(edge{node1, abs(c - x)});
      }
    }
  }
  puts("-1");
//  for(auto pr1 : G[0]) {
//    int p, q; tie(p, q) = pr1; // 0棟 p階 -> 1棟 q階への渡り廊下
//    int node1 = corr0_rev[0][p];
//    H[M].push_back(edge{node1, abs(S - p)});
//  }
//  for(auto pr0 : G[N-2]) {
//    int b, c; tie(b, c) = pr0; // N-2棟 b階 -> N-1棟 c階への渡り廊下
//    int node0 = corr0_rev[N-2][b];
//    H[node0].push_back(edge{M+1, abs(c - T)});
//  }
//
//  // コーナーケース
//  if(N == 1) {
//    H[M].push_back(edge{M+1, abs(S - T)});
//  }
//
//  vector<i64> cost(M+2, inf); // cost[M+2]
//  cost[M] = 0;
//  priority_queue<pair<i64, int>, vector<pair<i64, int>>, greater<pair<i64, int>>> pq;
//  vector<bool> seen(M+2, false); // seen[M+2]
//  // コスト、点番号
//  pq.emplace(0, M);
//  while(!pq.empty()) {
//    i64 _, v; tie(_, v) = pq.top(); pq.pop();
//    if(seen[v]) { continue; }
//    seen[v] = true;
//    for(edge e : H[v]) {
//      if(cost[e.to] > cost[v] + e.cost) {
//        cost[e.to] = cost[v] + e.cost;
//        pq.emplace(cost[e.to], e.to);
//      }
//    }
//  }
//  i64 res = cost[M+1];
//  if(res == inf) { res = -1; }
//  printf("%lld\n", res);
  return 0;
}
0