結果

問題 No.2222 Respawn
ユーザー rabimearabimea
提出日時 2023-02-17 23:22:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 201,016 KB
実行使用メモリ 473,984 KB
最終ジャッジ日時 2023-09-26 20:46:31
合計ジャッジ時間 21,440 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
7,676 KB
testcase_02 AC 4 ms
15,920 KB
testcase_03 AC 6 ms
24,196 KB
testcase_04 AC 7 ms
30,188 KB
testcase_05 AC 3 ms
9,740 KB
testcase_06 AC 2 ms
5,628 KB
testcase_07 AC 2 ms
5,532 KB
testcase_08 AC 42 ms
159,452 KB
testcase_09 AC 39 ms
159,168 KB
testcase_10 AC 39 ms
159,372 KB
testcase_11 AC 36 ms
158,164 KB
testcase_12 AC 39 ms
159,136 KB
testcase_13 AC 698 ms
378,600 KB
testcase_14 AC 483 ms
306,288 KB
testcase_15 AC 261 ms
232,748 KB
testcase_16 AC 445 ms
292,552 KB
testcase_17 AC 276 ms
229,508 KB
testcase_18 AC 1,035 ms
473,840 KB
testcase_19 AC 997 ms
473,772 KB
testcase_20 AC 997 ms
473,892 KB
testcase_21 AC 991 ms
473,872 KB
testcase_22 AC 980 ms
473,948 KB
testcase_23 AC 1,089 ms
473,804 KB
testcase_24 AC 1,060 ms
473,804 KB
testcase_25 AC 1,058 ms
473,740 KB
testcase_26 AC 1,048 ms
473,984 KB
testcase_27 AC 1,050 ms
473,872 KB
testcase_28 AC 1,069 ms
473,880 KB
testcase_29 AC 1,091 ms
473,876 KB
testcase_30 AC 1,073 ms
473,880 KB
testcase_31 AC 955 ms
473,880 KB
testcase_32 AC 1,096 ms
473,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}

0