結果

問題 No.867 避難経路
ユーザー FF256grhyFF256grhy
提出日時 2019-08-16 23:05:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,211 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 175,964 KB
実行使用メモリ 69,928 KB
最終ジャッジ日時 2023-10-24 04:25:46
合計ジャッジ時間 120,054 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
6,276 KB
testcase_01 AC 54 ms
6,276 KB
testcase_02 AC 55 ms
6,276 KB
testcase_03 AC 53 ms
6,276 KB
testcase_04 AC 53 ms
6,276 KB
testcase_05 AC 63 ms
44,472 KB
testcase_06 AC 64 ms
66,560 KB
testcase_07 AC 62 ms
58,528 KB
testcase_08 AC 62 ms
58,528 KB
testcase_09 AC 62 ms
58,528 KB
testcase_10 AC 62 ms
58,528 KB
testcase_11 AC 62 ms
58,528 KB
testcase_12 AC 62 ms
58,528 KB
testcase_13 AC 62 ms
58,528 KB
testcase_14 AC 63 ms
58,528 KB
testcase_15 AC 4,475 ms
69,928 KB
testcase_16 AC 4,480 ms
69,928 KB
testcase_17 AC 4,524 ms
69,928 KB
testcase_18 AC 4,422 ms
69,928 KB
testcase_19 AC 4,385 ms
69,928 KB
testcase_20 AC 4,362 ms
69,928 KB
testcase_21 AC 4,323 ms
69,928 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 WA -
testcase_31 AC 4,066 ms
69,928 KB
testcase_32 AC 3,902 ms
69,928 KB
testcase_33 AC 3,901 ms
69,928 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 60 ms
66,560 KB
testcase_42 AC 62 ms
66,560 KB
testcase_43 AC 61 ms
66,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)

// ---- ----

template<typename T> class RPQ : public priority_queue<T, vector<T>, greater<T>> { };
template<typename C> void dijkstra(int s, vector<pair<int, C>> g[], C d[]) {
	RPQ<pair<C, int>> q;
	d[s] = 0;
	q.emplace(d[s], s);
	while(! q.empty()) {
		C   c = q.top().FI;
		int v = q.top().SE;
		q.pop();
		if(d[v] != c) { continue; }
		for(auto & e : g[v]) {
			int ev = e.FI;
			C   ec = e.SE;
			if(setmin(d[ev], d[v] + ec)) { q.emplace(d[ev], ev); }
		}
	}
}

const int M = 251;
const int L = 250;
int h, w, gi, gj, a[M][M], q, d[L + 1][M * M], INF = 1e9;

int id(int i, int j) { return (w + 1) * i + j; }

int main() {
	cin >> h >> w >> gi >> gj;
	gi--; gj--;
	inc(i, h) {
	inc(j, w) {
		cin >> a[i][j];
	}
	}
	
	inc1(k, L) {
		vector<pair<int, int>> g[M * M];
		
		g[id(h, w)].EB(id(gi, gj), a[gi][gj] + k * k);
		inc(i, h) {
		inc(j, w) {
			g[id(i, j)].EB(id(i + 1, j), a[i + 1][j] + k * k);
			g[id(i, j)].EB(id(i, j + 1), a[i][j + 1] + k * k);
			g[id(i + 1, j)].EB(id(i, j), a[i][j] + k * k);
			g[id(i, j + 1)].EB(id(i, j), a[i][j] + k * k);
		}
		}
		
		inc(i, h + 1) {
		inc(j, w + 1) {
			d[k][id(i, j)] = INF;
		}
		}
		
		dijkstra(id(h, w), g, d[k]);
	}
	
	cin >> q;
	inc(qq, q) {
		int si, sj, k;
		cin >> si >> sj >> k;
		si--; sj--;
		
		int p = abs(si - gi) + abs(sj - gj) + 1;
		
		cout << d[min(k, L)][id(si, sj)] + (k < L ? 0 : p * (k * k - L * L)) << "\n";
	}
	
	return 0;
}
0