結果
| 問題 |
No.659 徘徊迷路
|
| コンテスト | |
| ユーザー |
はまやんはまやん
|
| 提出日時 | 2018-03-02 23:36:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 3,056 bytes |
| コンパイル時間 | 2,254 ms |
| コンパイル使用メモリ | 179,260 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 12:30:41 |
| 合計ジャッジ時間 | 4,100 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 12 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
typedef vector<double> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
int n = b.size(); Vec ret(n, 0);
rep(i, 0, n) rep(j, 0, n) ret[i] += a[i][j] * b[j];
return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
int n = a.size(); Mat ret(n, Vec(n, 0));
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] += a[i][k] * b[k][j];
return ret;
}
Mat fastpow(Mat x, ll n)
{
Mat ret(x.size(), Vec(x.size(), 0));
rep(i, 0, x.size()) ret[i][i] = 1;
while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
return ret;
}
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H, W, T, SY, SX, GY, GX;
string B[10];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W >> T >> SY >> SX >> GY >> GX;
rep(y, 0, H) cin >> B[y];
Vec v(100);
v[SY * 10 + SX] = 1;
Mat m(100, Vec(100));
rep(y, 0, H) rep(x, 0, W) if(B[y][x] == '.'){
int cnt = 0;
rep(i, 0, 4) {
int xx = x + dx[i];
int yy = y + dy[i];
if (0 <= xx and xx < W and 0 <= yy and yy < H) {
if (B[yy][xx] == '.') cnt++;
}
}
if (cnt == 0) {
m[y * 10 + x][y * 10 + x] = 1;
continue;
}
double p = 1.0 / (double)cnt;
rep(i, 0, 4) {
int xx = x + dx[i];
int yy = y + dy[i];
if (0 <= xx and xx < W and 0 <= yy and yy < H) if (B[yy][xx] == '.') {
m[yy * 10 + xx][y * 10 + x] = p;
}
}
}
v = mulMatVec(fastpow(m, T), v);
//rep(y, 0, H) rep(x, 0, W) printf("[%d][%d] = %.10f\n", y, x, v[y * 10 + x]);
double ans = v[GY * 10 + GX];
printf("%.10f\n", ans);
}
はまやんはまやん