結果
| 問題 | No.2222 Respawn | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-02-17 23:22:17 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,164 ms / 2,000 ms | 
| コード長 | 1,250 bytes | 
| コンパイル時間 | 2,145 ms | 
| コンパイル使用メモリ | 196,520 KB | 
| 最終ジャッジ日時 | 2025-02-10 18:12:39 | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 30 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using vl = vector <ll>;
using pii = pair <int, int>;
const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }
const int N = 2e5 + 11;
const int M = 100;
int n;
string s;
double a[M + 2][N], b[M + 2][N], f[M + 2][N];
int main() {
	ios::sync_with_stdio(0);
	int n; cin >> n;
	
	cin >> s;
	s = '#' + s + "##";
	
	for(int j = n - 1; j >= 1; j --) {
		for(int i = min(n - 1, j + M - 1); i >= j; i --) {
			for(int t : {1, 2})
				if(s[i + t] == '#') {
					a[i - j][j] += 1.0 / 3; 
				} else {
					a[i - j][j] += a[i - j + t][j] / 3;
					b[i - j][j] += b[i - j + t][j] / 3;
				}
			
			if(i != j)
				b[i - j][j] += f[0][i] / 3;
			else
				a[i - j][j] += 1.0 / 3;
			b[i - j][j] += 1;
			//~ cout << i << ' ' << j << ' ' << a[i - j][j] << ' ' << b[i - j][j] << '\n';
		}
		
		f[0][j] = b[0][j] / (1 - a[0][j]);
		for(int i = min(n, j + M - 1); i > j; i --)
			f[i - j][j] = a[i - j][j] * f[0][j] + b[i - j][j];
	}
	
	cout << fixed << setprecision(8) << f[0][1] << '\n';
}
            
            
            
        