結果

問題 No.867 避難経路
ユーザー b312546656b312546656
提出日時 2019-08-16 22:34:50
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 3,564 ms / 6,000 ms
コード長 3,311 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 94,808 KB
実行使用メモリ 44,544 KB
最終ジャッジ日時 2024-09-22 19:00:15
合計ジャッジ時間 94,820 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 4 ms
5,248 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3,390 ms
44,544 KB
testcase_16 AC 3,278 ms
44,416 KB
testcase_17 AC 3,470 ms
44,416 KB
testcase_18 AC 3,289 ms
44,416 KB
testcase_19 AC 3,224 ms
44,544 KB
testcase_20 AC 3,160 ms
44,544 KB
testcase_21 AC 3,056 ms
44,416 KB
testcase_22 AC 3,191 ms
44,544 KB
testcase_23 AC 3,406 ms
44,416 KB
testcase_24 AC 3,108 ms
44,416 KB
testcase_25 AC 3,259 ms
44,544 KB
testcase_26 AC 3,270 ms
44,416 KB
testcase_27 AC 3,280 ms
44,416 KB
testcase_28 AC 3,435 ms
44,416 KB
testcase_29 AC 3,564 ms
44,544 KB
testcase_30 AC 3,021 ms
44,416 KB
testcase_31 AC 3,351 ms
44,544 KB
testcase_32 AC 3,201 ms
44,416 KB
testcase_33 AC 3,171 ms
44,416 KB
testcase_34 AC 3,118 ms
44,416 KB
testcase_35 AC 3,242 ms
44,416 KB
testcase_36 AC 3,268 ms
44,032 KB
testcase_37 AC 3,121 ms
41,728 KB
testcase_38 AC 3,101 ms
41,856 KB
testcase_39 AC 3,095 ms
41,856 KB
testcase_40 AC 3,063 ms
41,856 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 3 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
/*int p = 998244353;*/
int p = 1000000007;
#define vel vector<int>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_pr(s) cout << s <<endl;return 0
#define itn int
int RE() {
vel v(3, 2);
return v.at(4);
}
int ru(int a, int r) {
if (r == 0) { return 1; }
int ans = ru(a, r / 2);
ans *= ans; ans %= p;
if (r % 2 == 1) { ans *= a; }
return ans % p;
}
int inv(int a) {
return ru(a,p - 2);
}
vel dis(int mid1, vvel &way) {
int n = way.size();
vel dist(n, -1); dist[mid1] = 0;
queue<int> q;
q.push(mid1);
while (!q.empty()) {
int st = q.front(); q.pop();
rep(i, way[st].size()) {
int to = way[st][i];
if (dist[to] == -1) {
dist[to] = dist[st] + 1;
q.push(to);
}
}
}
return dist;
}
pin most_far(int now, int n, vvel &way) {
vel dist1 = dis(now, way);
pin ans = mkp(-1, 0);
rep(i, n) {
if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
}
return ans;
}
template<typename T>
V<T> uni(V<T> &v) {
if (v.size() == 0) { return v; }
sor(v);
V<T> ans(1, v[0]);
for (int i = 1; i < v.size(); i++) {
if (v[i] != v[i - 1]) { ans.push_back(v[i]); }
}
v = ans;
return v;
}
int s_gcd(int a, int b) {
if (b == 0) { return a; }
return s_gcd(b, a%b);
}
int gcd(int a, int b) {
a = abs(a);
b = abs(b);
if (a < b) { swap(a, b); }
return s_gcd(a, b);
}
int solve(int sum, int lim) {
if (sum <= lim) { return sum - 1; }
if (sum > lim * 2) { return 0; }
return lim * 2 - sum+1;
}
vel dx{ 1,-1,0,0 };
vel dy{ 0,0,1,-1 };
vvel dijk(vvel &a, int h, int w, int k,int gx,int gy) {
priority_queue<qin,vector<qin>,greater<qin>> pq;
vvel dist(h, vel(w, -1));
pq.push(mkp(0, mkp(gx, gy)));
while (!pq.empty()) {
qin sm = pq.top(); pq.pop();
pin pot = sm.second;
int x = pot.first;
int y = pot.second;
int dis1 = sm.first;
if (dist[x][y] == -1) {
dist[x][y] = dis1;
rep(i, 4) {
int mx = x + dx[i];
int my = y + dy[i];
if (0 <= mx and mx < h and 0 <= my and my < w) {
if (dist[mx][my] == -1) {
pq.push(mkp(dis1 + k * k + a[mx][my], mkp(mx, my)));
}
}
}
}
}
rep(i, h) { rep(j, w) { dist[i][j] += (k * k + a[gx][gy]); } }
return dist;
}
int upper = 160;
signed main() {
int h, w; cin >> h >> w;
int gx, gy; cin >> gx >> gy;
gx--; gy--;
vvel a(h, vel(w));
rep(i, h) { rep(j, w) { cin >> a[i][j]; } }
V<vvel> dist(upper+1, vvel(h, vel(w)));
for (int k = 1; k <= upper; k++) {
dist[k] = dijk(a, h, w, k,gx,gy);
}
int q; cin >> q;
rep(i, q) {
int x, y;long long k; cin >> x >> y >> k; x--; y--;
if (k <= upper) {
cout << dist[k][x][y] << endl;
}
else {
int qans = dist[upper][x][y];
int c_dis = abs(x - gx) + abs(y - gy);
c_dis++;
long long mul = k*k-(upper*upper);
mul *= c_dis;
long long ret = qans;
ret += mul;
cout << ret << endl;
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0