結果
問題 | No.867 避難経路 |
ユーザー |
![]() |
提出日時 | 2019-08-16 22:59:33 |
言語 | C++11 (gcc 8.5.0) |
結果 |
AC
|
実行時間 | 5,423 ms / 6,000 ms |
コード長 | 2,139 bytes |
コンパイル時間 | 1,110 ms |
使用メモリ | 426,148 KB |
最終ジャッジ日時 | 2022-11-22 11:36:43 |
合計ジャッジ時間 | 90,497 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 17 ms
22,068 KB |
testcase_01 | AC | 16 ms
22,136 KB |
testcase_02 | AC | 17 ms
22,072 KB |
testcase_03 | AC | 17 ms
22,064 KB |
testcase_04 | AC | 17 ms
22,060 KB |
testcase_05 | AC | 17 ms
22,072 KB |
testcase_06 | AC | 16 ms
22,160 KB |
testcase_07 | AC | 16 ms
22,140 KB |
testcase_08 | AC | 16 ms
22,096 KB |
testcase_09 | AC | 16 ms
22,148 KB |
testcase_10 | AC | 17 ms
22,148 KB |
testcase_11 | AC | 17 ms
22,120 KB |
testcase_12 | AC | 17 ms
22,136 KB |
testcase_13 | AC | 17 ms
22,124 KB |
testcase_14 | AC | 17 ms
22,068 KB |
testcase_15 | AC | 3,646 ms
425,764 KB |
testcase_16 | AC | 3,570 ms
426,028 KB |
testcase_17 | AC | 3,539 ms
426,024 KB |
testcase_18 | AC | 3,482 ms
426,036 KB |
testcase_19 | AC | 3,543 ms
426,096 KB |
testcase_20 | AC | 1,573 ms
426,112 KB |
testcase_21 | AC | 1,599 ms
426,024 KB |
testcase_22 | AC | 4,578 ms
426,140 KB |
testcase_23 | AC | 4,200 ms
426,116 KB |
testcase_24 | AC | 4,199 ms
426,076 KB |
testcase_25 | AC | 5,203 ms
426,024 KB |
testcase_26 | AC | 5,423 ms
426,036 KB |
testcase_27 | AC | 5,239 ms
426,148 KB |
testcase_28 | AC | 5,396 ms
426,096 KB |
testcase_29 | AC | 5,342 ms
426,092 KB |
testcase_30 | AC | 1,664 ms
426,024 KB |
testcase_31 | AC | 1,660 ms
426,080 KB |
testcase_32 | AC | 1,653 ms
426,036 KB |
testcase_33 | AC | 1,667 ms
426,072 KB |
testcase_34 | AC | 1,661 ms
424,432 KB |
testcase_35 | AC | 1,666 ms
424,512 KB |
testcase_36 | AC | 1,653 ms
421,108 KB |
testcase_37 | AC | 1,603 ms
410,932 KB |
testcase_38 | AC | 1,622 ms
410,924 KB |
testcase_39 | AC | 1,606 ms
410,956 KB |
testcase_40 | AC | 1,600 ms
410,952 KB |
testcase_41 | AC | 9 ms
12,076 KB |
testcase_42 | AC | 12 ms
17,096 KB |
testcase_43 | AC | 13 ms
17,084 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; typedef pair<ll, P> Pl; const ll INF=1e18; int h, w; int gx, gy; int a[252][252]; ll dp[801][252][252]; ll d[51][252][252]; int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1}; int main() { cin>>h>>w; cin>>gx>>gy; gx--; gy--; for(int i=0; i<h; i++){ for(int j=0; j<w; j++){ cin>>a[i][j]; } } for(int i=0; i<=800; i++){ for(int j=0; j<h; j++){ for(int k=0; k<w; k++){ dp[i][j][k]=INF; } } } dp[0][gx][gy]=a[gx][gy]; for(int i=0; i<800; i++){ for(int j=0; j<h; j++){ for(int k=0; k<w; k++){ for(int l=0; l<4; l++){ int x1=j+dx[l], y1=k+dy[l]; if(x1<0 || x1>=h || y1<0 || y1>=w) continue; dp[i+1][x1][y1]=min(dp[i][j][k]+a[x1][y1], dp[i+1][x1][y1]); } } } } for(int k=1; k<=50; k++){ for(int i=0; i<h; i++){ for(int j=0; j<w; j++) d[k][i][j]=INF; } d[k][gx][gy]=k*k+a[gx][gy]; priority_queue<Pl, vector<Pl>, greater<Pl>> que; que.push({d[k][gx][gy], {gx, gy}}); while(!que.empty()){ Pl p=que.top(); que.pop(); int x=p.second.first, y=p.second.second; if(d[k][x][y]<p.first) continue; for(int l=0; l<4; l++){ int x1=x+dx[l], y1=y+dy[l]; if(x1<0 || x1>=h || y1<0 || y1>=w) continue; if(d[k][x1][y1]>d[k][x][y]+k*k+a[x1][y1]){ d[k][x1][y1]=d[k][x][y]+k*k+a[x1][y1]; que.push({d[k][x1][y1], {x1, y1}}); } } } } int q; cin>>q; for(int i=0; i<q; i++){ int x, y; ll k; scanf("%d %d %lld", &x, &y, &k); x--; y--; if(k<=50){ printf("%lld\n", d[k][x][y]); }else{ int d0=abs(x-gx)+abs(y-gy); ll ans=INF; for(ll j=d0; j<=d0+300; j++){ ans=min(ans, dp[j][x][y]+k*k*(j+1)); } printf("%lld\n", ans); } } return 0; }