結果
問題 | No.867 避難経路 |
ユーザー | chocorusk |
提出日時 | 2019-09-28 11:22:06 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1,436 ms / 6,000 ms |
コード長 | 2,138 bytes |
コンパイル時間 | 1,054 ms |
コンパイル使用メモリ | 109,396 KB |
実行使用メモリ | 302,232 KB |
最終ジャッジ日時 | 2024-04-09 19:41:57 |
合計ジャッジ時間 | 43,325 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 20 ms
65,884 KB |
testcase_01 | AC | 20 ms
65,616 KB |
testcase_02 | AC | 21 ms
67,804 KB |
testcase_03 | AC | 20 ms
65,880 KB |
testcase_04 | AC | 20 ms
65,628 KB |
testcase_05 | AC | 20 ms
65,760 KB |
testcase_06 | AC | 20 ms
65,740 KB |
testcase_07 | AC | 21 ms
65,504 KB |
testcase_08 | AC | 21 ms
65,756 KB |
testcase_09 | AC | 21 ms
65,884 KB |
testcase_10 | AC | 21 ms
65,880 KB |
testcase_11 | AC | 21 ms
65,756 KB |
testcase_12 | AC | 21 ms
69,724 KB |
testcase_13 | AC | 21 ms
69,724 KB |
testcase_14 | AC | 21 ms
69,724 KB |
testcase_15 | AC | 1,436 ms
301,980 KB |
testcase_16 | AC | 1,314 ms
302,024 KB |
testcase_17 | AC | 1,287 ms
302,020 KB |
testcase_18 | AC | 1,188 ms
301,980 KB |
testcase_19 | AC | 1,196 ms
302,020 KB |
testcase_20 | AC | 1,028 ms
301,892 KB |
testcase_21 | AC | 1,011 ms
302,016 KB |
testcase_22 | AC | 1,252 ms
302,112 KB |
testcase_23 | AC | 1,254 ms
302,024 KB |
testcase_24 | AC | 1,229 ms
301,896 KB |
testcase_25 | AC | 1,334 ms
301,976 KB |
testcase_26 | AC | 1,330 ms
301,980 KB |
testcase_27 | AC | 1,323 ms
302,148 KB |
testcase_28 | AC | 1,318 ms
302,020 KB |
testcase_29 | AC | 1,334 ms
302,148 KB |
testcase_30 | AC | 982 ms
302,020 KB |
testcase_31 | AC | 983 ms
302,020 KB |
testcase_32 | AC | 982 ms
302,024 KB |
testcase_33 | AC | 978 ms
302,148 KB |
testcase_34 | AC | 983 ms
301,508 KB |
testcase_35 | AC | 996 ms
301,376 KB |
testcase_36 | AC | 982 ms
300,120 KB |
testcase_37 | AC | 957 ms
299,072 KB |
testcase_38 | AC | 942 ms
301,980 KB |
testcase_39 | AC | 943 ms
301,872 KB |
testcase_40 | AC | 941 ms
302,232 KB |
testcase_41 | AC | 59 ms
300,524 KB |
testcase_42 | AC | 60 ms
300,792 KB |
testcase_43 | AC | 60 ms
300,668 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:85:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 85 | scanf("%d %d %lld", &x, &y, &k); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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[551][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<=550; 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<550; 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+50; j++){ ans=min(ans, dp[j][x][y]+k*k*(j+1)); } printf("%lld\n", ans); } } return 0; }