結果

問題 No.2222 Respawn
ユーザー no way
提出日時 2023-02-18 16:01:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 166,584 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-07-20 02:00:02
合計ジャッジ時間 3,252 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
double f[N][2],g[N][2],h[N][2];
char s[N];
int n;
int main(){
	scanf("%d",&n);
	scanf("%s",s);
	g[n-1][1]=1; f[n-1][1]=1;
	for (int i=n-2;i>=0;i--)if (s[i]=='.'){
		if (i+1>n-1||s[i+1]=='#'){
			h[i][0]+=1.0/3;
			h[i][1]+=1.0/3;
		}else{
			h[i][0]+=h[i+1][0]/3+h[i+1][1]/3;
			h[i][1]+=h[i+1][1]/3;
		}
		if (i+2>n-1||s[i+2]=='#'){
			h[i][0]+=1.0/3;
			h[i][1]+=1.0/3;			
		}else{
			h[i][0]+=h[i+2][0]/3+h[i+2][1]/3;
			h[i][1]+=h[i+2][1]/3;
		}
		double p=h[i][1]+1.0/3;
		double e=1.0/(1.0-p)*(h[i][0]+1.0/3)/(1.0-p);
		p=1.0/(1.0-p);
		double p1,e1;
		e1=(g[i+1][1]+g[i+1][0]+g[i+2][0]+g[i+2][1])/3;
		p1=(g[i+1][1]+g[i+2][1])/3;
		f[i][1]=p1*p;
		f[i][0]=p*e1+p1*e;
		g[i][1]=f[i][1]/3+p1;
		g[i][0]=f[i][0]/3+f[i][1]/3+e1;
	}
	printf("%.8lf\n",f[0][0]);
}
0