結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
homesentinel
|
| 提出日時 | 2018-03-02 23:57:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 146 ms / 2,000 ms |
| コード長 | 3,677 bytes |
| コンパイル時間 | 1,587 ms |
| コンパイル使用メモリ | 127,828 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-22 23:20:53 |
| 合計ジャッジ時間 | 3,131 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 |
ソースコード
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x) cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif
//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
typedef vector<long double> vec;
typedef vector<vec> mat;
mat mul(mat &A, mat &B) {
mat C(A.size(), vec(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] = (C[i][j] + A[i][k] * B[k][j]);
}
}
}
return C;
}
mat pow(mat A, ll n) {
mat B(A.size(), vec(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 main() {
cin.tie(0);
ios::sync_with_stdio(false);
int R, C, T;
cin >> R >> C >> T;
int sx, sy, gx, gy;
cin >> sy >> sx >> gy >> gx;
vector<vector<char> > B(R, vector<char>(C));
vector<vector<int> > vv(R, vector<int>(C));
rep(i, 0, R) {
rep(j, 0, C) {
char c;
cin >> c;
B[i][j] = c;
}
}
auto conv = [&](int x, int y) {
return y * C + x;
};
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
rep(i, 0, R) {
rep(j, 0, C) {
if (B[i][j] == '#') continue;
rep(k, 0, 4) {
if (B[i + dy[k]][j + dx[k]] != '#')
vv[i][j]++;
}
}
}
if(vv[sy][sx] == 0){
if(sy == gy && sx == gx){
printf("%.7Lf\n",1.0L);
}else{
printf("%.7Lf\n",0.0L);
}
return 0;
}
vec b(R * C);
b[conv(sx, sy)] = 1.0;
mat A(R * C, vec(R * C));
// rep(i,0,R){
// rep(j,0,C){
// if(B[i][j] != '#'){
// rep(k,0,4){
// A[i][j] += 1.0/vv[i+dy[k]][j+dx[k]];
// }
// }
// }
// }
rep(i, 0, R) {
rep(j, 0, C) {
if (B[i][j] != '#') {
rep(k, 0, 4) {
if (vv[i + dy[k]][j + dx[k]] != 0)
A[conv(j, i)][conv(j + dx[k], i + dy[k])] = 1.0 / vv[i + dy[k]][j + dx[k]];
}
}
}
}
A = pow(A, T);
// cout << A[conv(gx, gy)][conv(sx, sy)] << endl;
printf("%.7Lf\n",A[conv(gx, gy)][conv(sx, sy)]);
return 0;
}
homesentinel