結果

提出番号 895
提出者 kotatsugame
言語 C++
提出日時 2017-08-01 15:34:03
問題名 (44)玉ねぎの収穫をするkotamanegi
結果 WA
点数 0%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 23ms 11056KB
2 WA 0% 18ms 8496KB
3 WA 0% 42ms 12640KB
4 WA 0% 48ms 17184KB
5 AC 100% 38ms 10656KB
6 WA 0% 121ms 19248KB
7 WA 0% 3ms 7504KB
8 WA 0% 44ms 10896KB
9 AC 100% 52ms 18256KB
10 AC 100% 49ms 12208KB
11 AC 100% 37ms 12864KB
12 AC 100% 15ms 16128KB
13 WA 0% 49ms 11440KB
14 AC 100% 23ms 12048KB
15 WA 0% 144ms 19952KB
16 WA 0% 7ms 8304KB
17 WA 0% 37ms 13552KB
18 AC 100% 41ms 15504KB
19 AC 100% 38ms 10000KB
20 AC 100% 4ms 10000KB

ソースコード

#include<iostream>
#include<queue>
using namespace std;
int h,w,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int x[1001],y[1001];
int gx,gy;
int yl,yr,xl,xr;
int d[1001][1001];
main()
{
	cin>>h>>w>>gx>>gy;
	for(int i=0;i++<h;)cin>>x[i];
	for(int i=0;i++<w;)cin>>y[i];
	cin>>yl>>yr>>xl>>xr;
	for(int i=0;i++<h;)for(int j=0;j++<w;)d[i][j]=1e9;
	d[1][1]=0;
	queue<pair<int,int> >P;
	P.push(make_pair(1,1));
	while(!P.empty())
	{
		int nx=P.front().first,ny=P.front().second;
		P.pop();
		for(int r=0;r<4;r++)
		{
			int tx=nx+dx[r],ty=ny+dy[r];
			if(tx<=0||ty<=0||tx>h||ty>w)continue;
			if(xl<=tx&&tx<=xr&&yl<=ty&&ty<=yr)continue;
			int cost=d[nx][ny]+(r%2?x[nx]:y[ny]);
			if(d[tx][ty]>cost)
			{
				d[tx][ty]=cost;
				P.push(make_pair(tx,ty));
			}
		}
	}
	if(d[gx][gy]<1e9)cout<<d[gx][gy]<<endl;
	else cout<<-1<<endl;
}