結果

問題 No.2354 Poor Sight in Winter
ユーザー momoyuumomoyuu
提出日時 2023-07-12 14:58:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,342 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 150,740 KB
実行使用メモリ 7,512 KB
最終ジャッジ日時 2023-10-12 05:15:04
合計ジャッジ時間 4,520 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 WA -
testcase_12 AC 146 ms
7,276 KB
testcase_13 AC 161 ms
7,488 KB
testcase_14 AC 158 ms
7,436 KB
testcase_15 AC 152 ms
7,360 KB
testcase_16 AC 154 ms
7,512 KB
testcase_17 AC 155 ms
7,376 KB
testcase_18 AC 69 ms
5,504 KB
testcase_19 AC 113 ms
6,784 KB
testcase_20 AC 78 ms
5,796 KB
testcase_21 WA -
testcase_22 AC 32 ms
4,348 KB
testcase_23 AC 33 ms
4,348 KB
testcase_24 AC 101 ms
6,336 KB
testcase_25 AC 24 ms
4,348 KB
testcase_26 AC 18 ms
4,348 KB
testcase_27 AC 3 ms
4,352 KB
testcase_28 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
#include<map>
#include<functional>
//#include<bits/stdc++.h>
using namespace std;
using ll = long long;


template< typename T >
struct edge{
    int from,to;
    T cost;
    edge(int from,int to, T cost):from(from),to(to),cost(cost){};
    edge &operator=(const int& x){
        to = x;
        return *this;
    }
};

template< typename T >
struct graph{
    int n;
    vector<vector<edge<T>>> e;
    graph(int n):n(n),e(n){}

    void addedge(int from,int to,T cost){
        e[from].emplace_back(from,to,cost);
    }

    vector<edge<T>> &operator[](int i) {
        return e[i];
    }
};

/*
 * O(ElogV)
 * 蛻ー驕比ク崎・縺ョ蝣エ蜷医・窶・縺悟・縺」縺ヲ繧九€・ */
template< typename T >
vector<T> dijkstra(graph<T>& g, int st){
    int n = g.n;
    using pt = pair<T,int>;
    vector<T> dist(n,-1);
    dist[st] = 0;
    priority_queue<pt, vector<pt>, greater<pt>>que;
    que.emplace(0,st);
    while(que.size()){
        int ni;
        T cost;
        tie(cost,ni) = que.top();
        que.pop();
        if(dist[ni]<cost&&dist[ni]!=-1) continue;
        for(edge<T> itr:g[ni]){
            int nxt = itr.to;
            if(dist[nxt]>cost+itr.cost||dist[nxt]==-1){
                dist[nxt] = cost + itr.cost;
                que.emplace(dist[nxt],nxt);
            }
        }
    }
    return dist;
};

int main(){
    int n,k,sx,sy,gx,gy;
    cin>>n>>k>>sx>>sy>>gx>>gy;
    vector<int> x(n),y(n);
    for(int i = 0;i<n;i++) cin>>x[i]>>y[i];
    ll right = 1e9;
    ll left = 0;
    while(right-left>1){
        ll mid = (right+left)/2;
        graph<ll> g(n+2);
        int s = n;
        int t = s + 1;
        for(int i = 0;i<n;i++){
            int now = abs(sx-x[i]) + abs(sy-y[i]) - 1;
            g.addedge(s,i,now/mid);
            now = abs(x[i]-gx) + abs(y[i]-gy) - 1;
            g.addedge(i,t,now/mid);
            for(int j = i + 1;j<n;j++){
                int now = abs(x[i]-x[j]) + abs(y[i]-y[j]) - 1;
                g.addedge(i,j,now/mid);
                g.addedge(j,i,now/mid);
            }
        }
        ll can = dijkstra<ll>(g,s)[t];
        if(can<=k) right = mid;
        else left = mid;
    }
    cout<<right<<endl;

}
0