結果

問題 No.867 避難経路
ユーザー heno239heno239
提出日時 2019-08-16 22:55:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,131 bytes
コンパイル時間 2,992 ms
コンパイル使用メモリ 123,896 KB
実行使用メモリ 397,920 KB
最終ジャッジ日時 2023-10-24 03:34:53
合計ジャッジ時間 62,873 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,776 KB
testcase_01 AC 5 ms
12,756 KB
testcase_02 AC 5 ms
12,732 KB
testcase_03 AC 5 ms
12,772 KB
testcase_04 AC 6 ms
12,776 KB
testcase_05 AC 5 ms
12,732 KB
testcase_06 AC 5 ms
12,732 KB
testcase_07 AC 6 ms
12,772 KB
testcase_08 AC 6 ms
12,764 KB
testcase_09 AC 6 ms
12,776 KB
testcase_10 AC 5 ms
12,732 KB
testcase_11 AC 5 ms
12,732 KB
testcase_12 AC 5 ms
12,788 KB
testcase_13 AC 6 ms
12,772 KB
testcase_14 AC 6 ms
12,732 KB
testcase_15 AC 2,696 ms
389,880 KB
testcase_16 AC 2,235 ms
371,796 KB
testcase_17 AC 2,440 ms
397,920 KB
testcase_18 AC 2,376 ms
382,332 KB
testcase_19 AC 2,268 ms
371,000 KB
testcase_20 AC 2,267 ms
374,908 KB
testcase_21 AC 1,991 ms
344,588 KB
testcase_22 AC 2,237 ms
372,156 KB
testcase_23 AC 2,322 ms
396,392 KB
testcase_24 AC 2,059 ms
350,172 KB
testcase_25 AC 2,241 ms
376,240 KB
testcase_26 AC 2,160 ms
374,420 KB
testcase_27 AC 2,371 ms
385,928 KB
testcase_28 AC 2,340 ms
388,288 KB
testcase_29 AC 2,217 ms
390,628 KB
testcase_30 AC 1,721 ms
324,868 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,743 ms
324,044 KB
testcase_35 AC 1,798 ms
323,848 KB
testcase_36 AC 1,708 ms
321,524 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 4 ms
10,584 KB
testcase_42 AC 5 ms
10,648 KB
testcase_43 AC 4 ms
10,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
};

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();
		}
	}
	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);
	}
	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;
}
0