結果

提出番号 960
提出者 Yang33
言語 C++
提出日時 2017-08-01 16:29:56
問題名 (44)玉ねぎの収穫をするkotamanegi
結果 WA
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 WA 0% 52ms 19760KB
2 WA 0% 38ms 12240KB
3 WA 0% 63ms 22304KB
4 WA 0% 118ms 31392KB
5 WA 0% 40ms 18320KB
6 WA 0% 212ms 39744KB
7 WA 0% 4ms 8304KB
8 WA 0% 64ms 18784KB
9 WA 0% 42ms 28832KB
10 WA 0% 51ms 21424KB
11 WA 0% 81ms 22640KB
12 WA 0% 8ms 18352KB
13 WA 0% 63ms 19872KB
14 WA 0% 24ms 19072KB
15 WA 0% 182ms 41120KB
16 WA 0% 6ms 8640KB
17 WA 0% 67ms 24080KB
18 WA 0% 59ms 26240KB
19 WA 0% 46ms 17008KB
20 WA 0% 7ms 11232KB

ソースコード

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/08/01  Problem: KotamanegiOJ_Otemae F  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N;

ll ans = LINF;
ll W, H, Ty, Tx;
int cx[1003];
int cy[1003];
ll yl, yr, xl, xr;
ll masu[1003][1003];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> H >> W >> Tx >> Ty;
	FOR(i, 1, H + 1) {
		cin >> cx[i];
	}
	FOR(i, 1, W + 1) {
		cin >> cy[i];
	}
	cin >> xl >> xr >> yl >> yr;
	FOR(i, 0, H+1)FOR(j, 0, W+1) {
		masu[i][j] = LINF;
	}
	masu[1][1] = 0;
	using tt = tuple<ll, ll, ll>;
	priority_queue<tt, vector<tt>, greater<tt>>q;
	q.push(tt(0, 1, 1));

	while (!q.empty()) {
		tt a = q.top(); q.pop();
		ll d, x, y;
		tie(d, y, x) = a;
		if (masu[y][x] < d)continue;

		FOR(i, 0, 4) {
			int nx = x + dx[i]; int ny = y + dy[i];
			if (!(1 <= nx&&nx <= H && 1 <= ny&&ny <= W))continue;

			if (xl <= nx && nx <= xr&&yl <= ny && ny <= yr)continue;
			ll nc;
			if (i < 2) {//y
				nc = cx[x];
			}
			else {//x
				nc = cy[y];
			}
			if (masu[nx][ny] > d + nc) {
				masu[nx][ny] = d + nc;
				q.push(tt(masu[nx][ny], ny, nx));
			}
		}
	}

	FOR(i, 1, H + 1) {
		FOR(j, 1, W + 1) {
			cout << masu[i][j] << " ";
		}cout << endl;
	}
	ans = masu[Ty][Tx];

	if (ans == LINF)ans = -1;
	cout << ans << endl;

	return 0;
}