結果

問題 No.867 避難経路
ユーザー tempura_pptempura_pp
提出日時 2019-08-16 23:04:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,974 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 108,428 KB
実行使用メモリ 29,648 KB
最終ジャッジ日時 2023-10-24 04:15:58
合計ジャッジ時間 33,188 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 1,159 ms
28,012 KB
testcase_16 AC 1,081 ms
27,616 KB
testcase_17 AC 1,130 ms
27,632 KB
testcase_18 AC 1,085 ms
27,528 KB
testcase_19 AC 1,075 ms
27,480 KB
testcase_20 AC 443 ms
24,216 KB
testcase_21 AC 440 ms
24,268 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1,306 ms
23,968 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,345 ms
23,964 KB
testcase_35 AC 1,408 ms
23,940 KB
testcase_36 AC 1,406 ms
23,932 KB
testcase_37 AC 1,348 ms
23,908 KB
testcase_38 AC 1,364 ms
23,908 KB
testcase_39 AC 1,328 ms
23,908 KB
testcase_40 AC 1,324 ms
23,908 KB
testcase_41 AC 2 ms
4,372 KB
testcase_42 AC 2 ms
4,372 KB
testcase_43 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

struct query{
    ll sx,sy,id,k;
};

int main(){
    int h,w;
    cin>>h>>w;
    ll a[h][w];
    int gx,gy;
    cin>>gx>>gy;
    --gx;--gy;
    rep(i,h)rep(j,w)cin>>a[i][j];
    int q;
    cin>>q;
    vector<query> v[161];
    rep(i,q){
        int x,y,k;
        cin>>x>>y>>k;
        --x;--y;
        v[min(k,160)].push_back({x,y,i,k});
    }
    ll dist[300][300];
    int di[]={1,0,-1,0,1};
    vector<ll> ans(q);
    rep(K,161){
        if(v[K].empty())continue;
        rep(i,h)rep(j,w){
            dist[i][j]=longinf;
        }
        dist[gx][gy]=K*K+a[gx][gy];
        using T  =pair<ll,pair<int,int>>;
        priority_queue<T,vector<T>, greater<T>> pq;
        pq.push({dist[gx][gy],{gx,gy}});
        while(pq.size()){
            ll d = pq.top().first;
            auto p = pq.top().second;
            pq.pop();
            int x = p.first, y = p.second;
            if(dist[x][y]<d)continue;
            rep(i,4){
                int nx = x+di[i], ny=y+di[i+1]; 
                if(nx<0||nx>=h||ny<0||ny>=w)continue;
                if(dist[nx][ny]>d+a[nx][ny]+K*K){
                    dist[nx][ny]=d+a[nx][ny]+K*K;
                    pq.push({dist[nx][ny],{nx,ny}});
                }
            }
        }
        for(auto Q :v[K]){
            ans[Q.id]=dist[Q.sx][Q.sy];
            if(K!=Q.k){
                ll d = abs(Q.sx-gx)+(Q.sy-gy)+1;
                ans[Q.id]+=(Q.k*Q.k-K*K)*d;
            }
        }
    }
    for(auto e : ans)cout<<e<<"\n";
    return 0;
}
0