結果

問題 No.2222 Respawn
ユーザー no wayno way
提出日時 2023-02-18 16:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 164,444 KB
実行使用メモリ 13,224 KB
最終ジャッジ日時 2023-09-27 07:53:09
合計ジャッジ時間 5,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,640 KB
testcase_01 AC 2 ms
7,540 KB
testcase_02 AC 3 ms
7,688 KB
testcase_03 AC 2 ms
7,452 KB
testcase_04 AC 2 ms
7,456 KB
testcase_05 AC 3 ms
7,572 KB
testcase_06 AC 3 ms
7,452 KB
testcase_07 AC 2 ms
7,608 KB
testcase_08 AC 2 ms
7,556 KB
testcase_09 AC 2 ms
7,588 KB
testcase_10 AC 3 ms
7,464 KB
testcase_11 AC 2 ms
7,604 KB
testcase_12 AC 2 ms
7,612 KB
testcase_13 AC 9 ms
11,048 KB
testcase_14 AC 7 ms
11,228 KB
testcase_15 AC 5 ms
8,344 KB
testcase_16 AC 7 ms
11,036 KB
testcase_17 AC 5 ms
8,316 KB
testcase_18 AC 12 ms
13,076 KB
testcase_19 AC 13 ms
13,044 KB
testcase_20 AC 12 ms
13,032 KB
testcase_21 AC 12 ms
13,088 KB
testcase_22 AC 13 ms
13,008 KB
testcase_23 AC 14 ms
13,008 KB
testcase_24 AC 13 ms
13,156 KB
testcase_25 AC 14 ms
12,920 KB
testcase_26 AC 14 ms
13,008 KB
testcase_27 AC 13 ms
13,224 KB
testcase_28 AC 18 ms
13,088 KB
testcase_29 AC 17 ms
13,036 KB
testcase_30 AC 18 ms
13,004 KB
testcase_31 AC 13 ms
13,040 KB
testcase_32 AC 62 ms
13,116 KB
権限があれば一括ダウンロードができます

ソースコード

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