結果

問題 No.2222 Respawn
ユーザー Rubikun
提出日時 2023-09-20 18:51:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 1,932 ms
コンパイル使用メモリ 193,760 KB
最終ジャッジ日時 2025-02-16 23:41:05
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

double ans[MAX],dp0[MAX],dp1[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;cin>>N;
    string S;cin>>S;
    S+='#';
    
    dp1[N]=1;
    
    for(int j=N-2;j>=0;j--){
        if(S[j]=='#') dp1[j]=1;
        else{
            dp1[j]+=1.0/3;
            for(int t=1;t<=2;t++){
                dp0[j]+=dp0[j+t]/3;
                dp1[j]+=dp1[j+t]/3;
            }
            
            dp0[j]+=1.0;
            
            ans[j]=dp0[j]/(1.0-dp1[j]);
            
            dp1[j]-=1.0/3;
            dp0[j]+=ans[j]/3;
        }
        
        ans[j]=dp0[j]/(1.0-dp1[j]);
    }
    
    cout<<fixed<<setprecision(25)<<ans[0]<<endl;
    
}

0