結果

問題 No.2354 Poor Sight in Winter
ユーザー HIcoderHIcoder
提出日時 2023-07-04 21:41:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,553 ms / 2,000 ms
コード長 2,176 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 94,168 KB
実行使用メモリ 11,356 KB
最終ジャッジ日時 2023-09-25 20:59:21
合計ジャッジ時間 16,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1,424 ms
11,172 KB
testcase_12 AC 1,306 ms
10,492 KB
testcase_13 AC 1,553 ms
11,124 KB
testcase_14 AC 1,551 ms
11,312 KB
testcase_15 AC 1,537 ms
11,356 KB
testcase_16 AC 1,540 ms
11,116 KB
testcase_17 AC 1,535 ms
11,292 KB
testcase_18 AC 463 ms
6,840 KB
testcase_19 AC 971 ms
9,692 KB
testcase_20 AC 557 ms
7,248 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 237 ms
4,772 KB
testcase_23 AC 244 ms
4,948 KB
testcase_24 AC 830 ms
9,536 KB
testcase_25 AC 154 ms
4,380 KB
testcase_26 AC 110 ms
4,376 KB
testcase_27 AC 7 ms
4,380 KB
testcase_28 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:71:18: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   71 |             auto [d,v]=pq.top();
      |                  ^

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


struct edge{
    int to;
    int cost;
    edge(int to_,int cost_):to(to_),cost(cost_){};
};

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> x(N+2),y(N+2);
    cin>>x[0]>>y[0]>>x[N+1]>>y[N+1];

    for(int i=1;i<=N;i++){
        cin>>x[i]>>y[i];
    }    

    const int inf=1<<30;

    int ub=inf;//必ず到達が可能
    int lb=0;

    while(ub-lb>1){
        

        int mid=(ub+lb)/2;
        //cout<<"mid="<<mid<<endl;

        vector<vector<edge>> G(N+2);

        for(int i=0;i<N+2;i++){
            for(int j=0;j<N+2;j++){
                if(i==j) continue;
                int dist=abs(x[i]-x[j])+abs(y[i]-y[j]);

                int c=max((dist+(mid-1))/mid-1,0);

                G[i].emplace_back(j,c);
                G[j].emplace_back(i,c);

            }
        }


        //ここからダイクストラ
        vector<int> dp(N+10,inf);//dp[i]=iに到達するまでにdp[i]個のあかりを消費する

       
        priority_queue<P,vector<P>,greater<P>> pq;

        pq.emplace(0,0);

        while(!pq.empty()){
            auto [d,v]=pq.top();
            pq.pop();

            if(dp[v]<=d) continue;
            
            //dp[v]>d
            dp[v]=d;

            for(edge e:G[v]){
                if(dp[e.to]>(dp[v]+e.cost)){
                    pq.emplace(dp[v]+e.cost,e.to);
                }
            }

        }
        /*
        for(int i=0;i<=N+2;i++){
            cout<<"dp["<<i<<"]="<<dp[i]<<endl;
        }
        */

        if(dp[N+1]<=K){
            //家に到達できる場合
            ub=mid;
        }else{
            //家に到達できない
            lb=mid;
        }

        /*
        if(dp[N+1]>K){
            //家に到達できない場合
            lb=mid;
        }else{
            //家に到達できる
            ub=mid;
        }
        */
    }

    cout<<ub<<endl;

}
0