結果

問題 No.323 yuki国
ユーザー tailstails
提出日時 2015-12-18 09:18:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,011 bytes
コンパイル時間 1,214 ms
コンパイル使用メモリ 148,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 21:21:52
合計ジャッジ時間 2,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i=0;i<(n);++i)

char m[60][60];
char d[60][60];
int w,h,yu,gy,gx,b;

void g(priority_queue<int>&q,int a,int y,int x){
	if(y>=0&&y<h&&x>=0&&x<w){
		a+=m[y][x]==yu?1:-1;
		if(a>0||y==gy&&x==gx&&b==0){
			q.push(a<<16|y<<8|x);
		}
	}
}

bool f(int a,int y,int x,int b,int gy,int gx,int yu) {
	::gy=gy; ::gx=gx; ::yu=yu; ::b=b;
	priority_queue<int> q;
	g(q,a,y,x);
	rep(y,h)rep(x,w)d[y][x]=0;
	while(!q.empty()){
		int t=q.top();
		q.pop();
		a=t>>16;
		y=t>>8&255;
		x=t&255;
		if(y==gy&&x==gx&&a>=b){				
			return 1;
		}
		if(d[y][x]){
			if(d[y][x]<a){
				return 1;
			}
		}else{
			d[y][x]=a;
			g(q,a,y,x-1);
			g(q,a,y,x+1);
			g(q,a,y-1,x);
			g(q,a,y+1,x);
		}
	}
	return 0;
}

int main() {
	int a,si,sj,b,gi,gj,b1,b2;
	cin>>h>>w>>a>>si>>sj>>b>>gi>>gj;
	if(a+si+sj+b+gi+gj&1){
		b1=b2=0;
	}else{
		rep(y,h)cin>>m[y];
		a-=m[si][sj]=='*'?1:-1;
		b1=f(a,si,sj,b,gi,gj,'*');
		b2=f(b,gi,gj,a,si,sj,'.');
	}
	cout<<(b1&&b2?"Yes":"No");
}
0