結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
tempura_pp
|
| 提出日時 | 2018-06-24 15:00:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 2,000 ms |
| コード長 | 1,708 bytes |
| コンパイル時間 | 821 ms |
| コンパイル使用メモリ | 91,584 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 22:30:31 |
| 合計ジャッジ時間 | 1,727 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 |
ソースコード
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1};
typedef vector<vector<double> > mat;
int sz;
mat mul(mat A,mat B){
mat C(sz,vector<double>(sz));
rep(i,sz)rep(j,sz)rep(k,sz)C[i][j]+=A[i][k]*B[k][j];
return C;
}
mat pow(mat A,ll k){
mat B(sz,vector<double>(sz));
rep(i,sz)B[i][i]=1;
while(k>0){
if(k&1)B=mul(A,B);
A=mul(A,A);
k/=2;
}
return B;
}
int main(){
sz=64;
int n,m,t;
cin>>n>>m>>t;
int sx,sy,gx,gy;
cin>>sy>>sx>>gy>>gx;
string a[n];
rep(i,n)cin>>a[i];
mat A(sz,vector<double>(sz));
rep(i,n)rep(j,m){
if(a[i][j]=='.'){
int cnt=0;
if(a[i][j+1]=='.')cnt++;
if(a[i+1][j]=='.')cnt++;
if(a[i][j-1]=='.')cnt++;
if(a[i-1][j]=='.')cnt++;
if(cnt==0){A[8*(i-1)+j-1][8*(i-1)+j-1]=1.0;continue;}
if(a[i][j+1]=='.')A[8*(i-1)+j][8*(i-1)+j-1]=1.0/cnt;
if(a[i][j-1]=='.')A[8*(i-1)+j-2][8*(i-1)+j-1]=1.0/cnt;
if(a[i+1][j]=='.')A[8*i+j-1][8*(i-1)+j-1]=1.0/cnt;
if(a[i-1][j]=='.')A[8*(i-2)+j-1][8*(i-1)+j-1]=1.0/cnt;
}
}
A=pow(A,t);
cout<<fixed<<setprecision(10)<<A[8*(gy-1)+gx-1][8*(sy-1)+sx-1]<<endl;
return 0;
}
tempura_pp