結果
問題 | No.867 避難経路 |
ユーザー |
![]() |
提出日時 | 2019-08-16 23:13:04 |
言語 | C++14 (gcc 12.2.0 + boost 1.81.0) |
結果 |
AC
|
実行時間 | 3,840 ms / 6,000 ms |
コード長 | 3,886 bytes |
コンパイル時間 | 1,119 ms |
実行使用メモリ | 458,624 KB |
最終ジャッジ日時 | 2023-03-31 18:13:45 |
合計ジャッジ時間 | 98,247 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
10,632 KB |
testcase_01 | AC | 8 ms
10,468 KB |
testcase_02 | AC | 8 ms
10,528 KB |
testcase_03 | AC | 8 ms
10,532 KB |
testcase_04 | AC | 8 ms
10,484 KB |
testcase_05 | AC | 7 ms
10,460 KB |
testcase_06 | AC | 8 ms
10,564 KB |
testcase_07 | AC | 8 ms
10,480 KB |
testcase_08 | AC | 7 ms
10,576 KB |
testcase_09 | AC | 8 ms
10,532 KB |
testcase_10 | AC | 7 ms
10,460 KB |
testcase_11 | AC | 7 ms
10,596 KB |
testcase_12 | AC | 7 ms
10,524 KB |
testcase_13 | AC | 7 ms
10,552 KB |
testcase_14 | AC | 7 ms
10,560 KB |
testcase_15 | AC | 3,734 ms
450,484 KB |
testcase_16 | AC | 3,446 ms
432,452 KB |
testcase_17 | AC | 3,770 ms
458,624 KB |
testcase_18 | AC | 3,551 ms
442,880 KB |
testcase_19 | AC | 3,472 ms
431,508 KB |
testcase_20 | AC | 3,840 ms
435,420 KB |
testcase_21 | AC | 3,307 ms
405,140 KB |
testcase_22 | AC | 3,749 ms
432,612 KB |
testcase_23 | AC | 3,772 ms
457,064 KB |
testcase_24 | AC | 3,411 ms
410,688 KB |
testcase_25 | AC | 3,592 ms
436,764 KB |
testcase_26 | AC | 3,610 ms
434,928 KB |
testcase_27 | AC | 3,638 ms
446,624 KB |
testcase_28 | AC | 3,578 ms
448,876 KB |
testcase_29 | AC | 3,788 ms
451,380 KB |
testcase_30 | AC | 2,908 ms
385,380 KB |
testcase_31 | AC | 3,259 ms
423,100 KB |
testcase_32 | AC | 3,196 ms
413,692 KB |
testcase_33 | AC | 3,151 ms
407,328 KB |
testcase_34 | AC | 2,971 ms
384,608 KB |
testcase_35 | AC | 3,096 ms
384,572 KB |
testcase_36 | AC | 3,086 ms
381,652 KB |
testcase_37 | AC | 2,999 ms
370,080 KB |
testcase_38 | AC | 2,963 ms
370,280 KB |
testcase_39 | AC | 3,011 ms
370,256 KB |
testcase_40 | AC | 2,910 ms
370,372 KB |
testcase_41 | AC | 6 ms
8,868 KB |
testcase_42 | AC | 6 ms
9,532 KB |
testcase_43 | AC | 7 ms
9,768 KB |
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000009; const ll INF = mod * mod; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef pair<ll, ll> LP; typedef vector<ll> vec; typedef vector<string> svec; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-8; struct CHT { vector<LP> v; vector<LP> memo; int l; bool check(LP a, LP b, LP c) { return (b.first - a.first)*(c.second - b.second) >= (b.second - a.second)*(c.first - b.first); } void build(vector<LP> a) { l = 0; per(i, (int)a.size()) { while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], a[i]))v.pop_back(); v.push_back(a[i]); } } void build() { per(i, (int)memo.size()) { while (v.size() >= 2 && check(v[v.size() - 2], v[v.size() - 1], memo[i]))v.pop_back(); v.push_back(memo[i]); } memo.clear(); } void add(LP a) { memo.push_back(a); } ll f(LP a, ll x) { return a.first*x + a.second; } ll query(ll x) { while (l + 1 < v.size() && f(v[l], x) > f(v[l + 1], x))l++; return f(v[l], x); } }; const int sz = 505; int dx[4] = { 1,0,-1,0 }; int dy[4] = { 0,1,0,-1 }; int a[250][250]; int dist[250][250][sz+1]; CHT cht[250][250]; struct query { int x, y, k, id; }; int isans[250][250][250]; typedef pair<int, P> speP; void solve() { int h, w; cin >> h >> w; int sx, sy = 0; cin >> sx >> sy; sx--; sy--; rep(i, h) { rep(j, w) { cin >> a[i][j]; rep(k, sz + 1) { dist[i][j][k] = mod; } } } dist[sx][sy][1] = a[sx][sy]; //cht[sx][sy].add({ 1,a[sx][sy] }); Rep(k,2, sz + 1) { rep(i, h) { rep(j, w) { if (dist[i][j][k-1] == mod)continue; cht[i][j].add({ k-1,dist[i][j][k - 1] }); rep(t, 4) { int x = i + dx[t]; int y = j + dy[t]; if (x < 0 || y < 0 || x >= h || y >= w)continue; dist[x][y][k] = min(dist[x][y][k], dist[i][j][k - 1] + a[x][y]); } } } } rep(i, h) { rep(j, w) { cht[i][j].build(); } } for (int k = 1; k < 250; k++) { rep(i, h)rep(j, w)isans[k][i][j] = mod; isans[k][sx][sy] = k * k + a[sx][sy]; priority_queue<speP, vector<speP>, greater<speP>> q; q.push({ isans[k][sx][sy], { sx,sy } }); while (!q.empty()) { speP p = q.top(); q.pop(); int x = p.second.first, y = p.second.second; int val = p.first; if (val > isans[k][x][y])continue; rep(j, 4) { int nx = x + dx[j],ny = y + dy[j]; if (nx < 0 || ny < 0 || nx >= h || ny >= w)continue; int nd = val + k * k + a[nx][ny]; if (nd < isans[k][nx][ny]) { isans[k][nx][ny] = nd; q.push({ nd,{nx,ny} }); } } } } int q; cin >> q; vector<pair<P,P>> qmemo; rep(i, q) { int x, y, k; cin >> x >> y >> k; x--; y--; qmemo.push_back({ {k,i},{x,y} }); } sort(qmemo.begin(), qmemo.end()); vector<ll> ans(q); rep(i, q) { ll k = qmemo[i].first.first; int id = qmemo[i].first.second; int x = qmemo[i].second.first; int y = qmemo[i].second.second; ans[id] = cht[x][y].query(k*k); if (k < 250) { ans[id] = min(ans[id], (ll)isans[k][x][y]); } } rep(i, q) { cout << ans[i] << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init(); solve(); //cout << "finish" << endl; //stop return 0; }