結果

問題 No.1196 A lazy student
ユーザー SSRSSSRS
提出日時 2020-08-22 15:46:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 2,125 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 163,752 KB
実行使用メモリ 113,104 KB
最終ジャッジ日時 2024-04-23 10:01:46
合計ジャッジ時間 2,616 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 13 ms
5,376 KB
testcase_09 AC 28 ms
5,424 KB
testcase_10 AC 29 ms
5,484 KB
testcase_11 AC 27 ms
5,548 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 121 ms
113,104 KB
testcase_16 AC 38 ms
22,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
double number(string &S, int &p, double P, double Q, double R);
double factor(string &S, int &p, double P, double Q, double R);
double term1(string &S, int &p, double P, double Q, double R);
double term2(string &S, int &p, double P, double Q, double R);
double expression(string &S, int &p, double P, double Q, double R);
double number(string &S, int &p, double P, double Q, double R){
  if (S[p] == 'Y'){
    p++;
    return 1;
  } else {
    p++;
    return 0;
  }
}
double factor(string &S, int &p, double P, double Q, double R){
  if (S[p] == '('){
    p++;
    double ans = expression(S, p, P, Q, R);
    p++;
    return ans;
  } else {
    return number(S, p, P, Q, R);
  }
}
double term1(string &S, int &p, double P, double Q, double R){
  if (S[p] == 'r'){
    p += 2;
    double x = expression(S, p, P, Q, R);
    double y = expression(S, p, P, Q, R);
    p++;
    return x * y * P + (1 - x * y) * Q;
  } else {
    return factor(S, p, P, Q, R);
  }
}
double term2(string &S, int &p, double P, double Q, double R){
  double ans = term1(S, p, P, Q, R);
  while (1){
    if (S[p] == 'a'){
      p++;
      double tmp = term1(S, p, P, Q, R);
      ans = ans * tmp * (1 - R) + (1 - ans * tmp) * R;
    } else {
      break;
    }
  }
  return ans;
}
double expression(string &S, int &p, double P, double Q, double R){
  double ans = term2(S, p, P, Q, R);
  while (1){
    if (S[p] == 'o'){
      p++;
      double tmp = term2(S, p, P, Q, R);
      ans = (1 - (1 - ans) * (1 - tmp)) * (1 - R) + (1 - ans) * (1 - tmp) * R;
    } else {
      break;
    }
  }
  return ans;
}
int main(){
  int N;
  cin >> N;
  double P, Q, R;
  cin >> P >> Q >> R;
  string S;
  cin >> S;
  string T;
  for (int i = 0; i < N; i++){
    char c = S[i];
    T += c;
    if (c == 'o'){
      i++;
    }
    if (c == 'a'){
      i += 2;
    }
    if (c == 'r'){
      i += 5;
    }
    if (c == 'Y'){
      i += 2;
    }
    if (c == 'N'){
      i++;
    }
  }
  T += '$';
  int p = 0;
  double ans = expression(T, p, P, Q, R);
  cout << (int) (ans * 100 + EPS) << endl;
}
0