結果

問題 No.867 避難経路
ユーザー tempura_pptempura_pp
提出日時 2019-08-16 23:15:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,974 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 108,532 KB
実行使用メモリ 30,996 KB
最終ジャッジ日時 2023-10-24 05:09:40
合計ジャッジ時間 41,864 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 3 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1,101 ms
27,988 KB
testcase_16 AC 1,082 ms
27,592 KB
testcase_17 AC 1,143 ms
27,608 KB
testcase_18 AC 1,112 ms
27,504 KB
testcase_19 AC 1,091 ms
27,456 KB
testcase_20 AC 448 ms
24,192 KB
testcase_21 AC 447 ms
24,244 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 2,061 ms
23,952 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2,130 ms
23,948 KB
testcase_35 AC 2,260 ms
23,948 KB
testcase_36 AC 2,268 ms
23,940 KB
testcase_37 AC 2,122 ms
23,916 KB
testcase_38 AC 2,100 ms
23,916 KB
testcase_39 AC 2,101 ms
23,916 KB
testcase_40 AC 2,076 ms
23,916 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 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[501];
    rep(i,q){
        int x,y,k;
        cin>>x>>y>>k;
        --x;--y;
        v[min(k,300)].push_back({x,y,i,k});
    }
    ll dist[300][300];
    int di[]={1,0,-1,0,1};
    vector<ll> ans(q);
    rep(K,301){
        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