結果

問題 No.1599 Hikyaku
ユーザー 👑 NachiaNachia
提出日時 2021-07-10 16:09:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,486 ms / 7,500 ms
コード長 2,959 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 90,768 KB
実行使用メモリ 65,264 KB
最終ジャッジ日時 2023-09-14 19:37:22
合計ジャッジ時間 44,617 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 210 ms
62,664 KB
testcase_01 AC 248 ms
62,924 KB
testcase_02 AC 253 ms
62,940 KB
testcase_03 AC 260 ms
62,744 KB
testcase_04 AC 1,267 ms
64,920 KB
testcase_05 AC 526 ms
62,956 KB
testcase_06 AC 1,233 ms
64,732 KB
testcase_07 AC 603 ms
64,716 KB
testcase_08 AC 1,325 ms
64,716 KB
testcase_09 AC 474 ms
62,884 KB
testcase_10 AC 548 ms
62,768 KB
testcase_11 AC 425 ms
62,744 KB
testcase_12 AC 503 ms
64,288 KB
testcase_13 AC 366 ms
64,392 KB
testcase_14 AC 205 ms
62,748 KB
testcase_15 AC 224 ms
62,784 KB
testcase_16 AC 530 ms
62,796 KB
testcase_17 AC 1,276 ms
63,000 KB
testcase_18 AC 1,262 ms
62,940 KB
testcase_19 AC 1,389 ms
64,940 KB
testcase_20 AC 1,486 ms
64,764 KB
testcase_21 AC 1,362 ms
64,648 KB
testcase_22 AC 1,461 ms
64,664 KB
testcase_23 AC 1,371 ms
64,600 KB
testcase_24 AC 1,350 ms
64,576 KB
testcase_25 AC 1,382 ms
65,264 KB
testcase_26 AC 1,220 ms
64,332 KB
testcase_27 AC 826 ms
64,176 KB
testcase_28 AC 789 ms
63,560 KB
testcase_29 AC 576 ms
63,560 KB
testcase_30 AC 358 ms
62,800 KB
testcase_31 AC 208 ms
62,692 KB
testcase_32 AC 205 ms
62,616 KB
testcase_33 AC 216 ms
62,736 KB
testcase_34 AC 728 ms
62,884 KB
testcase_35 AC 1,040 ms
63,320 KB
testcase_36 AC 1,358 ms
63,520 KB
testcase_37 AC 1,326 ms
63,396 KB
testcase_38 AC 1,434 ms
63,416 KB
testcase_39 AC 1,327 ms
63,344 KB
testcase_40 AC 1,349 ms
63,640 KB
testcase_41 AC 161 ms
62,680 KB
testcase_42 AC 206 ms
62,608 KB
testcase_43 AC 162 ms
62,756 KB
testcase_44 AC 575 ms
62,788 KB
testcase_45 AC 553 ms
62,760 KB
testcase_46 AC 708 ms
62,696 KB
testcase_47 AC 732 ms
62,756 KB
testcase_48 AC 1,281 ms
62,744 KB
testcase_49 AC 210 ms
62,736 KB
testcase_50 AC 388 ms
62,740 KB
testcase_51 AC 550 ms
62,764 KB
testcase_52 AC 555 ms
63,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

template<class T>
using nega_queue = priority_queue<T,vector<T>,greater<T>>;

const int INF = 1001001001;

const int W = 600;
const int H = 600;
const int NV = W * H; // number of vertices
const int maxV = 7;

struct Start{ int id,v; };

int pos2id(int y,int x){ return y * W + x; }

int X,Y;
int N;
vector<Start> hikyaku;
double dt[maxV];
double V[maxV];
double T[maxV][NV];
vector<int> E[NV];

double D[maxV][NV];

int main(){
  cin >> X >> Y; X--; Y--;
  cin >> N;

  rep(y,H) rep(x,W-1) E[pos2id(y,x)].push_back(pos2id(y,x+1));
  rep(y,H) rep(x,W-1) E[pos2id(y,x+1)].push_back(pos2id(y,x));
  rep(y,H-1) rep(x,W) E[pos2id(y,x)].push_back(pos2id(y+1,x));
  rep(y,H-1) rep(x,W) E[pos2id(y+1,x)].push_back(pos2id(y,x));

  hikyaku.resize(N);
  rep(i,N){
    int x,y,v; cin >> x >> y >> v;
    x--; y--; v--;
    hikyaku[i] = { pos2id(y,x),v };
  }

  rep(v,maxV) V[v] = 1+v;
  rep(v,maxV) dt[v] = 1000.0 / (1+v);
  
  rep(v,maxV) rep(i,NV) T[v][i] = INF;

  {
    vector<vector<int>> I(maxV);
    for(auto a : hikyaku){
      I[a.v].push_back(a.id);
      T[a.v][a.id] = 0;
    }
    rep(v,maxV){
      rep(i,I[v].size()){
        int p = I[v][i];
        for(int e : E[p]) if(T[v][e] >= INF - 1.0){
          T[v][e] = T[v][p] + dt[v];
          I[v].push_back(e);
        }
      }
    }
  }
  
  rep(v,maxV) rep(i,NV) D[v][i] = INF;

  nega_queue<pair<double,pair<int,int>>> Q;
  D[hikyaku[0].v][hikyaku[0].id] = 0.0;
  Q.push(make_pair(0.0,make_pair(hikyaku[0].v,hikyaku[0].id)));

  while(Q.size()){
    double d = Q.top().first;
    int v = Q.top().second.first;
    int p = Q.top().second.second;
    Q.pop();
    if(D[v][p] != d) continue;
    for(int nxv=v+1; nxv<maxV; nxv++) if(D[nxv][p] > max(T[nxv][p],d)){
      D[nxv][p] = max(T[nxv][p],d);
      Q.push(make_pair(D[nxv][p],make_pair(nxv,p)));
    }
    for(int e : E[p]){
      if(D[v][e] > d + dt[v]){
        D[v][e] = d + dt[v];
        Q.push(make_pair(D[v][e],make_pair(v,e)));
      }
      double nxd = dt[v];
      int pv = v;
      for(int nxv=v+1; nxv<maxV; nxv++){
        double t0 = d + nxd - max(d - dt[nxv], T[nxv][e]);
        //cout << "p = " << p << ", e = " << e << ", pv = " << pv << ", nxv = " << nxv << ", t0 = " << t0 << endl;
        if(t0 < 0) continue;
        t0 = min(t0,dt[pv]+dt[nxv]);
        double t = nxd - t0 * (V[nxv] - V[pv]) / (V[nxv] + V[pv]);
        nxd = t; pv = nxv;
        if(D[nxv][e] <= d+nxd) continue;
        D[nxv][e] = d+nxd;
        Q.push(make_pair(d+nxd,make_pair(nxv,e)));
      }
    }
  }

  double ans = INF;
  rep(v,maxV) ans = min(ans,D[v][pos2id(Y,X)]);
  cout.precision(10); cout << fixed;
  cout << ans << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0