結果

問題 No.2354 Poor Sight in Winter
ユーザー umezoumezo
提出日時 2023-06-17 03:44:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 213,608 KB
実行使用メモリ 8,640 KB
最終ジャッジ日時 2023-09-07 02:26:41
合計ジャッジ時間 4,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 91 ms
8,416 KB
testcase_12 AC 99 ms
8,336 KB
testcase_13 AC 119 ms
8,580 KB
testcase_14 AC 114 ms
8,448 KB
testcase_15 AC 103 ms
8,640 KB
testcase_16 AC 104 ms
8,412 KB
testcase_17 AC 110 ms
8,508 KB
testcase_18 AC 44 ms
5,892 KB
testcase_19 AC 82 ms
7,416 KB
testcase_20 AC 53 ms
6,232 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 20 ms
4,376 KB
testcase_23 AC 22 ms
4,380 KB
testcase_24 AC 69 ms
6,916 KB
testcase_25 AC 15 ms
4,380 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const ll INF=1LL<<60;

struct Edge{
  int to;
  ll w;
  Edge(int to,ll w) : to(to),w(w) {}
};

using Graph=vector<vector<Edge>>;
using pli=pair<ll,int>;

template<class T> bool chmin(T& a,T b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}

vector<ll> dijkstra(int s,Graph &G){
  int n=G.size();
  vector<ll> dist(n,INF);
  dist[s]=0;
  
  priority_queue<pli,vector<pli>,greater<pli>> que;
  que.push({dist[s],s});
  
  while(!que.empty()){
    int v=que.top().second;
    ll d=que.top().first;
    que.pop();
    
    if(d>dist[v]) continue;
    
    for(auto e:G[v]){
      if(chmin(dist[e.to],dist[v]+e.w)){
        que.push({dist[e.to],e.to});
      }
    }
  }
  return dist;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,k;
  cin>>n>>k;
  int sx,sy,gx,gy;
  cin>>sx>>sy>>gx>>gy;
  vector<int> X(n+2),Y(n+2);
  X[0]=sx,Y[0]=sy;
  rep(i,n) cin>>X[i+1]>>Y[i+1];
  X[n+1]=gx,Y[n+1]=gy;
  vector<vector<int>> D(n+2,vector<int>(n+2));
  rep(i,n+2){
    rep(j,n+2) D[i][j]=abs(X[i]-X[j])+abs(Y[i]-Y[j]);
  }
  
  auto f=[&](int x)->int{
    Graph G(n+2);
    rep(i,n+2){
      for(int j=i+1;j<n+2;j++){
        int d=(D[i][j]-1)/x;
        G[i].push_back(Edge(j,d));
        G[j].push_back(Edge(i,d));
      }
    }
    vector<ll> dis=dijkstra(0,G);
    return dis[n+1];
  };
  
  int ok=200010,ng=0;
  while(ok-ng>1){
    int mid=(ok+ng)/2;
    if(f(mid)<=k) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
  
  return 0;
}
0