結果
問題 | No.867 避難経路 |
ユーザー | FF256grhy |
提出日時 | 2019-11-19 03:09:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,164 ms / 6,000 ms |
コード長 | 3,323 bytes |
コンパイル時間 | 2,408 ms |
コンパイル使用メモリ | 178,908 KB |
実行使用メモリ | 44,672 KB |
最終ジャッジ日時 | 2024-10-03 06:13:22 |
合計ジャッジ時間 | 88,379 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 4 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 4 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 4 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 5 ms
5,248 KB |
testcase_14 | AC | 4 ms
5,248 KB |
testcase_15 | AC | 3,016 ms
44,544 KB |
testcase_16 | AC | 2,870 ms
44,544 KB |
testcase_17 | AC | 2,941 ms
44,484 KB |
testcase_18 | AC | 2,892 ms
44,672 KB |
testcase_19 | AC | 2,888 ms
44,672 KB |
testcase_20 | AC | 2,834 ms
44,544 KB |
testcase_21 | AC | 2,817 ms
44,288 KB |
testcase_22 | AC | 3,017 ms
44,544 KB |
testcase_23 | AC | 3,122 ms
44,416 KB |
testcase_24 | AC | 3,024 ms
44,288 KB |
testcase_25 | AC | 3,019 ms
44,672 KB |
testcase_26 | AC | 3,049 ms
44,544 KB |
testcase_27 | AC | 3,062 ms
44,544 KB |
testcase_28 | AC | 3,150 ms
44,544 KB |
testcase_29 | AC | 3,164 ms
44,416 KB |
testcase_30 | AC | 2,839 ms
44,288 KB |
testcase_31 | AC | 2,826 ms
44,544 KB |
testcase_32 | AC | 2,884 ms
44,544 KB |
testcase_33 | AC | 2,866 ms
44,288 KB |
testcase_34 | AC | 2,831 ms
44,160 KB |
testcase_35 | AC | 2,954 ms
44,032 KB |
testcase_36 | AC | 2,885 ms
43,904 KB |
testcase_37 | AC | 2,819 ms
41,600 KB |
testcase_38 | AC | 2,830 ms
41,600 KB |
testcase_39 | AC | 2,811 ms
41,728 KB |
testcase_40 | AC | 2,781 ms
41,600 KB |
testcase_41 | AC | 3 ms
6,816 KB |
testcase_42 | AC | 3 ms
6,820 KB |
testcase_43 | AC | 3 ms
6,816 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(LL i = (l) ; i < (r); ++i) #define incII(i, l, r) for(LL i = (l) ; i <= (r); ++i) #define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i) #define decII(i, l, r) for(LL i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template<typename T> bool setmin (T & a, T b) { if(b < a) { a = b; return true; } else { return false; } } template<typename T> bool setmax (T & a, T b) { if(b > a) { a = b; return true; } else { return false; } } template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } } template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL >(v.size()) #define RF(e, v) for(auto & e: v) #define ef else if #define UR assert(false) // ---- ---- #define T0(T) T #define T1(T) vector<T0(T)> #define T2(T) vector<T1(T)> #define T3(T) vector<T2(T)> #define V0(v, T, ...) v #define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__)) #define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__)) #define V3(v, T, n, ...) T3(T)(n, V2(v, T, __VA_ARGS__)) #define GPQ priority_queue template<typename T> class LPQ : public GPQ<T, vector<T>, greater<T>> { }; const LL L = 159; int main() { int h, w, gi, gj; cin >> h >> w >> gi >> gj; gi--; gj--; auto a = V2(0, int, h, w); inc(i, h) { inc(j, w) { cin >> a[i][j]; } } auto d = V3(1e9, int, L + 1, h, w); LPQ<array<int, 4>> pq; auto update = [&](int k, int i, int j, int v) { if(setmin(d[k][i][j], v)) { pq.push({ d[k][i][j], k, i, j }); } }; incII(k, 0, L) { update(k, gi, gj, a[gi][gj] + k * k); } while(! pq.empty()) { auto e = pq.top(); pq.pop(); int v = e[0]; int k = e[1]; int i = e[2]; int j = e[3]; if(v != d[k][i][j]) { assert(v > d[k][i][j]); continue; } inc(l, 4) { int di[9] = { +1, 0, -1, 0, +1, +1, -1, -1, 0 }; int dj[9] = { 0, +1, 0, -1, +1, -1, +1, -1, 0 }; int ii = i + di[l]; int jj = j + dj[l]; if(! (inID(ii, 0, h) && inID(jj, 0, w))) { continue; } update(k, ii, jj, v + a[ii][jj] + k * k); } } int q; cin >> q; inc(qq, q) { LL i, j, k; cin >> i >> j >> k; i--; j--; LL ans = d[min(k, L)][i][j]; if(k > L) { ans += (abs(gi - i) + abs(gj - j) + 1) * (k * k - L * L); } cout << ans << "\n"; } return 0; }