結果

問題 No.659 徘徊迷路
ユーザー tempura_pptempura_pp
提出日時 2018-06-24 14:54:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,648 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 93,976 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-13 13:41:18
合計ジャッジ時間 2,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 6 ms
4,376 KB
testcase_02 AC 15 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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)continue;
            if(a[i][j+1]=='.')A[8*(i-1)+j+1][8*(i-1)+j]=1.0/cnt;            
            if(a[i][j-1]=='.')A[8*(i-1)+j-1][8*(i-1)+j]=1.0/cnt;            
            if(a[i+1][j]=='.')A[8*i+j][8*(i-1)+j]=1.0/cnt;            
            if(a[i-1][j]=='.')A[8*(i-2)+j][8*(i-1)+j]=1.0/cnt;            
        }
    }
    A=pow(A,t);
    cout<<fixed<<setprecision(10)<<A[8*(gy-1)+gx][8*(sy-1)+sx]<<endl;
    return 0;
}
0