結果

問題 No.1599 Hikyaku
ユーザー butsurizukibutsurizuki
提出日時 2021-05-11 04:37:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4,822 ms / 7,500 ms
コード長 3,859 bytes
コンパイル時間 3,130 ms
コンパイル使用メモリ 209,984 KB
実行使用メモリ 65,840 KB
最終ジャッジ日時 2023-09-14 06:59:12
合計ジャッジ時間 88,365 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
55,744 KB
testcase_01 AC 357 ms
61,172 KB
testcase_02 AC 512 ms
60,852 KB
testcase_03 AC 16 ms
56,024 KB
testcase_04 AC 61 ms
56,476 KB
testcase_05 AC 138 ms
57,416 KB
testcase_06 AC 4,334 ms
65,264 KB
testcase_07 AC 3,708 ms
65,776 KB
testcase_08 AC 2,402 ms
64,828 KB
testcase_09 AC 4,373 ms
60,924 KB
testcase_10 AC 4,142 ms
56,408 KB
testcase_11 AC 4,225 ms
55,952 KB
testcase_12 AC 1,050 ms
55,872 KB
testcase_13 AC 876 ms
56,020 KB
testcase_14 AC 70 ms
55,772 KB
testcase_15 AC 168 ms
55,768 KB
testcase_16 AC 16 ms
55,896 KB
testcase_17 AC 62 ms
56,604 KB
testcase_18 AC 448 ms
57,148 KB
testcase_19 AC 4,637 ms
65,840 KB
testcase_20 AC 4,664 ms
65,380 KB
testcase_21 AC 4,644 ms
57,580 KB
testcase_22 AC 4,670 ms
57,536 KB
testcase_23 AC 4,734 ms
56,532 KB
testcase_24 AC 4,761 ms
56,388 KB
testcase_25 AC 4,822 ms
56,144 KB
testcase_26 AC 3,989 ms
56,144 KB
testcase_27 AC 2,085 ms
55,864 KB
testcase_28 AC 2,076 ms
55,992 KB
testcase_29 AC 1,318 ms
56,048 KB
testcase_30 AC 431 ms
55,940 KB
testcase_31 AC 191 ms
55,828 KB
testcase_32 AC 105 ms
55,824 KB
testcase_33 AC 251 ms
56,068 KB
testcase_34 AC 678 ms
55,928 KB
testcase_35 AC 1,331 ms
55,860 KB
testcase_36 AC 2,053 ms
55,932 KB
testcase_37 AC 2,059 ms
56,056 KB
testcase_38 AC 2,070 ms
56,056 KB
testcase_39 AC 2,055 ms
56,236 KB
testcase_40 AC 2,086 ms
57,012 KB
testcase_41 AC 17 ms
55,800 KB
testcase_42 AC 158 ms
55,900 KB
testcase_43 AC 140 ms
55,764 KB
testcase_44 AC 17 ms
55,804 KB
testcase_45 AC 27 ms
55,956 KB
testcase_46 AC 17 ms
55,804 KB
testcase_47 AC 17 ms
56,024 KB
testcase_48 AC 17 ms
55,776 KB
testcase_49 AC 17 ms
55,860 KB
testcase_50 AC 16 ms
55,784 KB
testcase_51 AC 17 ms
55,880 KB
testcase_52 AC 821 ms
55,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

const double eps=1.0e-9;

using namespace std;
using pi=pair<int,int>;
using pdpi=pair<double,pi>;

int main(){
  int x,y;
  cin >> x >> y;
  x--;y--;
  int rd=x*600+y;

  int n;
  cin >> n;
  vector<int> sx(n),sy(n),sv(n);
  double dp[393939][16];
  for(int i=0;i<393939;i++){
    for(int j=0;j<16;j++){
      dp[i][j]=1.0e9;
    }
  }
  double len[32];
  for(int i=1;i<32;i++){len[i]=1000.0/((double)i);}

  priority_queue<pdpi,vector<pdpi>,greater<pdpi>> pq;
  for(int i=0;i<n;i++){
    cin >> sx[i] >> sy[i] >> sv[i];
    sx[i]--;sy[i]--;
    if(i){
      if(dp[sx[i]*600+sy[i]][sv[i]]>0.0){
        dp[sx[i]*600+sy[i]][sv[i]]=0.0;
        pq.push({0.0,{sx[i]*600+sy[i],sv[i]}});
      }
    }
    else{
      if(dp[sx[i]*600+sy[i]][7+sv[i]]>0.0){
        dp[sx[i]*600+sy[i]][7+sv[i]]=0.0;
        pq.push({0.0,{sx[i]*600+sy[i],7+sv[i]}});
      }
    }
  }
  double lh[393939];
  for(int i=0;i<393939;i++){lh[i]=-1.0;}

  while(!pq.empty()){
    pdpi od=pq.top();pq.pop();
    int vp=od.second.first;
    int vt=od.second.second;
    if(dp[vp][vt]<od.first){continue;}
    //if(vt>=8){
    //  cerr << od.first << ':';
    //  cerr << vp << ' ';
    //  cerr << vt << '\n';
    //}
    if(od.second.first==rd && vt>=8){
      printf("%.12lf\n",od.first);
      return 0;
    }
    if(vt>=8){
      if(lh[vp]<0.0){lh[vp]=od.first;}
      lh[vp]=min(lh[vp],od.first);
    }
    if(lh[vp]>=0.0){
      for(int i=1;i<=7;i++){
        if(dp[vp][i+7]>max(lh[vp],dp[vp][i])){
          dp[vp][i+7]=max(lh[vp],dp[vp][i]);
          pq.push({dp[vp][i+7],{vp,i+7}});
        }
      }
    }
    vector<int> kh;
    if(vp%600!=0){kh.push_back(vp-1);}
    if(vp%600!=599){kh.push_back(vp+1);}
    if((vp-600)>=0){kh.push_back(vp-600);}
    if((vp+600)<360000){kh.push_back(vp+600);}
    if(vt<=7){
      for(auto &nx : kh){
        if(dp[nx][vt]>od.first+len[vt]){
          dp[nx][vt]=od.first+len[vt];
          pq.push({od.first+len[vt],{nx,vt}});
        }
      }
    }
    else{
      for(auto &nx : kh){
        if(dp[nx][vt]>od.first+len[vt-7]){
          dp[nx][vt]=od.first+len[vt-7];
          pq.push({od.first+len[vt-7],{nx,vt}});
        }
      }
    }
    for(int sz=0;sz<2*kh.size();sz++){
      int pst=vp;
      int pfi=kh[sz%kh.size()];
      if(sz<kh.size()){swap(pst,pfi);}
      for(int i=8;i<=14;i++){
        int isp;
        if(i<=7){isp=i;}else{isp=i-7;}
        double cpos=0.0;
        double ctim=dp[pst][i];
        if(ctim==1.0e9){continue;}
        int jst,jfi;
        if(i<=7){jst=i+7+1;jfi=14;}
        else{jst=i-7+1;jfi=7;}

        while(jst<=jfi){
          bool fl=true;
          cpos=0.0;ctim=dp[pst][i];
          int csp=isp;
          for(int j=jst;j<=jfi;j++){
            int jsp;
            if(j<=7){jsp=j;}else{jsp=j-7;}
            if(dp[pfi][j]==1.0e9){continue;}
            double dist,delt,merg=0.0;
            dist=(1000.0-cpos);
            if(ctim>dp[pfi][j]){
              delt=ctim-dp[pfi][j];
              merg=delt;
              dist-=delt*jsp;
            }
            if(ctim<dp[pfi][j]){
              delt=dp[pfi][j]-ctim;
              merg=0.0;
              dist-=delt*csp;
            }
            if(dist<0.0){continue;}
            fl=false;
            if(ctim<dp[pfi][j]){
              cpos+=delt*csp;
              ctim=dp[pfi][j];
            }
            double nt=dist/(double)(csp+jsp);
            cpos+=(dist*csp)/(double)(csp+jsp);
            //cout << vp << ' ' << vt << ' ' << ctim+nt << ' ' <<cpos <<  ' ' << isp << ' ' << jsp << '\n';
            csp=jsp;
            ctim+=nt;
            nt+=ctim;
            nt+=merg;
            if(dp[pfi][jsp+7]>nt){
              dp[pfi][jsp+7]=nt;
              pq.push({nt,{pfi,jsp+7}});
            }
            jst=j+1;
          }
          if(fl){break;}
        }
      }
    }
  }
  return 0;
}
0