結果

問題 No.659 徘徊迷路
ユーザー PulmnPulmn
提出日時 2018-07-25 18:31:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 158,772 KB
実行使用メモリ 4,464 KB
最終ジャッジ日時 2023-09-09 04:04:42
合計ジャッジ時間 5,321 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 63 ms
4,388 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 93 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 105 ms
4,384 KB
testcase_09 AC 251 ms
4,380 KB
testcase_10 AC 291 ms
4,384 KB
testcase_11 AC 290 ms
4,384 KB
testcase_12 AC 54 ms
4,464 KB
testcase_13 AC 251 ms
4,380 KB
testcase_14 AC 251 ms
4,376 KB
testcase_15 AC 295 ms
4,380 KB
testcase_16 AC 296 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<27;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-18;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

vvd mul(vvd A,vvd B){
	vvd C(A.size(),vd(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) C[i][j]+=A[i][k]*B[k][j];
	return C;
}

vvd pow(vvd A,ll n){
	vvd B(A.size(),vd(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

int h,w,t,x,y,X,Y;
vvi a;

int main(){
	cin>>h>>w>>t>>x>>y>>X>>Y;
	a=vvi(h,vi(w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		char c;
		cin>>c;
		if(c=='#') a[i][j]++;
	}
	vvd A(h*w,vd(h*w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(!a[i][j]){
		int t=0;
		for(int k=0;k<4;k++){
			int cx=i+dx[k],cy=j+dy[k];
			if(!a[cx][cy]) t++;
		}
		if(!t){
			A[i*w+j][i*w+j]+=1;
			continue;
		}
		for(int k=0;k<4;k++){
			int cx=i+dx[k],cy=j+dy[k];
			if(!a[cx][cy]){
				A[cx*w+cy][i*w+j]+=1.0/t;
			}
		}
	}
	cout<<syosu(9)<<pow(A,t)[X*w+Y][x*w+y]<<endl;
	A=pow(A,t);
}
0