結果

問題 No.1196 A lazy student
ユーザー snow39snow39
提出日時 2020-09-02 22:14:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 1,729 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 90,872 KB
実行使用メモリ 65,708 KB
最終ジャッジ日時 2023-08-14 04:27:44
合計ジャッジ時間 2,361 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 58 ms
65,708 KB
testcase_16 AC 12 ms
14,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘ld constant(int&)’ 内:
main.cpp:89:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   89 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

typedef long double ld;

int N;
long double P,Q,R;
string S;

ld expression(int &i);
ld term(int &i);
ld factor(int &i);
ld constant(int &i);

ld expression(int &i){
  return term(i);
}

ld term(int &i){
  ld result=factor(i);
  while(i<S.size()){
    if(S[i]=='o'){
      i+=2;
      ld rig=factor(i);

      ld res=(1-result)*(1-rig)*R+(1-(1-result)*(1-rig))*(1-R);
      result=res;
    }else{
      break;
    }
  }
  return result;
}

ld factor(int &i){
  ld result=constant(i);
  while(i<S.size()){
    if(S[i]=='a'){
      i+=3;
      ld rig=constant(i);

      ld res=result*rig*(1-R)+(1-result*rig)*R;
      result=res;
    }else{
      break;
    }
  }
  return result;
}

ld constant(int &i){
  if(S[i]=='Y'){
    i+=3;
    return 1;
  }else if(S[i]=='N'){
    i+=2;
    return 0;
  }else if(S[i]=='r'){
    i+=6;
    i++;//'('
    ld x=expression(i);
    ld y=expression(i);
    i++;//')'
    ld res=x*y*P+(1-x*y)*Q;
    return res;
  }else if(S[i]=='('){
    i++;
    ld res=expression(i);
    i++;
    return res;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N;
  cin>>P>>Q>>R;
  cin>>S;

  int i=0;
  ld ans=expression(i);
  ans*=100;
  int output=round(ans+0.1);
  cout<<output<<endl;


  return 0;
}
0