結果

問題 No.2222 Respawn
ユーザー RubikunRubikun
提出日時 2023-09-20 18:51:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 199,080 KB
実行使用メモリ 9,104 KB
最終ジャッジ日時 2023-09-20 18:52:00
合計ジャッジ時間 4,629 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,508 KB
testcase_01 AC 2 ms
5,572 KB
testcase_02 AC 2 ms
5,572 KB
testcase_03 AC 2 ms
5,516 KB
testcase_04 AC 2 ms
5,676 KB
testcase_05 AC 2 ms
5,644 KB
testcase_06 AC 2 ms
5,648 KB
testcase_07 AC 2 ms
5,676 KB
testcase_08 AC 2 ms
5,680 KB
testcase_09 AC 2 ms
5,672 KB
testcase_10 AC 2 ms
5,584 KB
testcase_11 AC 2 ms
5,664 KB
testcase_12 AC 2 ms
5,576 KB
testcase_13 AC 7 ms
7,848 KB
testcase_14 AC 5 ms
7,284 KB
testcase_15 AC 3 ms
6,484 KB
testcase_16 AC 5 ms
7,016 KB
testcase_17 AC 4 ms
6,428 KB
testcase_18 AC 9 ms
9,052 KB
testcase_19 AC 9 ms
9,036 KB
testcase_20 AC 9 ms
9,040 KB
testcase_21 AC 9 ms
8,916 KB
testcase_22 AC 9 ms
9,088 KB
testcase_23 AC 11 ms
9,056 KB
testcase_24 AC 11 ms
9,092 KB
testcase_25 AC 11 ms
9,032 KB
testcase_26 AC 11 ms
8,920 KB
testcase_27 AC 11 ms
9,104 KB
testcase_28 AC 12 ms
9,032 KB
testcase_29 AC 11 ms
8,904 KB
testcase_30 AC 11 ms
8,932 KB
testcase_31 AC 8 ms
9,096 KB
testcase_32 AC 11 ms
9,060 KB
権限があれば一括ダウンロードができます

ソースコード

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