結果
問題 | No.659 徘徊迷路 |
ユーザー | ryoissy |
提出日時 | 2018-03-02 22:53:43 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,673 bytes |
コンパイル時間 | 1,387 ms |
コンパイル使用メモリ | 161,840 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2024-06-22 04:55:33 |
合計ジャッジ時間 | 2,539 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 17 | scanf("%d%d%d",&r,&c,&t); | ~~~~~^~~~~~~~~~~~~~~~~~~ main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d%d",&sy,&sx); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:19:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | scanf("%d%d",&gy,&gx); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int r,c,t; int fie[11][11]; int sx,sy; int gx,gy; double per[35][11][11][11][11]; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; double dp[2][11][11]; int main(void){ scanf("%d%d%d",&r,&c,&t); scanf("%d%d",&sy,&sx); scanf("%d%d",&gy,&gx); for(int i=0;i<r;i++){ string str; cin >> str; for(int j=0;j<c;j++){ if(str[j]=='#'){ fie[i][j]=-1; } } } for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ if(fie[i][j]==0){ int cnt=0; for(int k=0;k<4;k++){ int nx=j+dx[k]; int ny=i+dy[k]; if(nx>=0 && nx<c && ny>=0 && ny<r){ if(fie[ny][nx]==0)cnt++; } } if(cnt==0){ per[0][i][j][i][j]=1.0; }else{ for(int k=0;k<4;k++){ int nx=j+dx[k]; int ny=i+dy[k]; if(nx>=0 && nx<c && ny>=0 && ny<r){ if(fie[ny][nx]==0)per[0][i][j][ny][nx]=(double)1.0/cnt; } } } } } } for(int i=0;i<30;i++){ for(int j=0;j<r;j++){ for(int k=0;k<c;k++){ for(int a=0;a<r;a++){ for(int b=0;b<c;b++){ for(int a2=0;a2<r;a2++){ for(int b2=0;b2<c;b2++){ per[i+1][j][k][a2][b2]+=per[i][j][k][a][b]*per[i][a][b][a2][b2]; } } } } } } } int cur=0,next=1; dp[cur][sy][sx]=1.0; for(int i=0;i<30;i++){ if(t>>i & 1){ for(int j=0;j<r;j++){ for(int k=0;k<c;k++){ for(int a=0;a<r;a++){ for(int b=0;b<c;b++){ dp[next][a][b]+=dp[cur][j][k]*per[i][j][k][a][b]; } } } } swap(cur,next); memset(dp[next],0,sizeof(dp[next])); } } printf("%.10f\n",dp[cur][gy][gx]); return 0; }