結果

問題 No.1196 A lazy student
ユーザー tnakao0123tnakao0123
提出日時 2020-08-24 18:32:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 1,000 ms
コード長 1,578 bytes
コンパイル時間 990 ms
コンパイル使用メモリ 90,704 KB
実行使用メモリ 50,680 KB
最終ジャッジ日時 2023-08-06 07:36:22
合計ジャッジ時間 2,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 10 ms
4,464 KB
testcase_10 AC 10 ms
4,604 KB
testcase_11 AC 10 ms
4,424 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 45 ms
50,680 KB
testcase_16 AC 13 ms
11,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1196.cc:  No.1196 A lazy student - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
double p, q, r;

/* subroutines */

double expr(char *(&cpt));

double elm(char *(&cpt)) {
  if (*cpt == 'Y') {
    cpt += 3; // 'YES'
    return 1.0;
  }

  if (*cpt == 'N') {
    cpt += 2; // 'NO'
    return 0.0;
  }

  if (*cpt == '(') {
    cpt++; // '('
    double e0 = expr(cpt);
    cpt++; // ')'
    return e0;
  }

  cpt += 7; // 'random('
  double e0 = expr(cpt);
  double e1 = expr(cpt);
  cpt++; // ')'

  return (e0 * e1) * p + (1.0 - e0 * e1) * q;
}

double term(char *(&cpt)) {
  double e0 = elm(cpt);
  while (*cpt == 'a') {
    cpt += 3; // 'and'
    double e1 = elm(cpt);
    e0 *= e1;
    e0 = r * e0 + (1.0 - r) * (1.0 - e0);
  }
  return e0;
}

double expr(char *(&cpt)) {
  double e0 = term(cpt);
  while (*cpt == 'o') {
    cpt += 2; // 'or'
    double e1 = term(cpt);
    e0 = 1.0 - (1.0 - e0) * (1.0 - e1);
    e0 = r * e0 + (1.0 - r) * (1.0 - e0);
  }
  return e0;
}

/* main */

int main() {
  int n;
  scanf("%d%lf%lf%lf%s", &n, &p, &q, &r, s);

  char *cpt = s;
  double e = expr(cpt);
  printf("%d\n", (int)(e * 100));
  return 0;
}
0