結果

提出番号 908
提出者 puni
言語 C++
提出日時 2017-08-01 15:42:11
問題名 (44)玉ねぎの収穫をするkotamanegi
結果 CE
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 CE 0% 0ms 0KB
2 CE 0% 0ms 0KB
3 CE 0% 0ms 0KB
4 CE 0% 0ms 0KB
5 CE 0% 0ms 0KB
6 CE 0% 0ms 0KB
7 CE 0% 0ms 0KB
8 CE 0% 0ms 0KB
9 CE 0% 0ms 0KB
10 CE 0% 0ms 0KB
11 CE 0% 0ms 0KB
12 CE 0% 0ms 0KB
13 CE 0% 0ms 0KB
14 CE 0% 0ms 0KB
15 CE 0% 0ms 0KB
16 CE 0% 0ms 0KB
17 CE 0% 0ms 0KB
18 CE 0% 0ms 0KB
19 CE 0% 0ms 0KB
20 CE 0% 0ms 0KB

ソースコード

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

bool inside(int a, int b, int alim, int blim){
	return 0 <= a && a < alim && 0 <= b && b < blim;
}

bool inside2(int a, int b, int amin, int amax, int bmin, int bmax){
	return amin <= a && a <= amax && bmin <= b && b <= bmax;
}

int main(){
	int h, w, x, y;
	cin >> h >> w >> x >> y;
	pair<int, int> goal(--x, --y);
	int a[h], b[w];
	for(int i = 0; i < h; i++) cin >> a[i];
	for(int i = 0; i < w; i++) cin >> b[i];
	int c, d, e, f;
	cin >> c >> d >> e >> f;
	c--; d--; e--; f--;
	priority_queue<pair<int64_t, pair<int, int>>, vector<pair<int64_t, pair<int, int>>>, greater<pair<int64_t, pair<int, int>>>> pq;
	pq.push(make_pair(0, make_pair(0, 0)));
	int dd[] = {0, 1, 0, -1, 0};
	bool done[h][w]{};
	int64_t score[h][w];
	fill(score[0], score[h], 1ll << 60);
	score[0][0] = 0;
	while(!pq.empty()){
		auto puni = pq.top();
		pq.pop();
		int64_t cost = puni.first;
		pair<int, int> now = puni.second;
		if(done[now.first][now.second]) continue;
		done[now.first][now.second] = true;
		for(int i = 0; i < 4; i++){
			pair<int, int> next(now.first + dd[i], now.second + dd[i + 1]);
			if(inside(next.first, next.second, h, w) && !inside2(next.first, next.second, c, d, e, f) && score[now.first][now.second] + (abs(now.first - next.first) ? b[now.second] : a[now.first]) < score[next.first][next.second]){
				score[next.first][next.second] = score[now.first][now.second] + (abs(now.first - next.first) ? b[now.second] : a[now.first]);
				pq.push(make_pair(score[next.first][next.second], next));
			}
		}
	}
	cout << (score[h - 1][w - 1] == 1ll << 60 ? -1 : score[h - 1][w - 1]) << endl;
}