結果

問題 No.298 話の伝達
ユーザー motimoti
提出日時 2015-11-13 21:38:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,618 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 106,920 KB
実行使用メモリ 6,268 KB
最終ジャッジ日時 2023-10-11 15:48:40
合計ジャッジ時間 2,003 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 WA -
testcase_05 AC 18 ms
4,372 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,372 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,368 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define minimize(a, x) a = std::min(a, x)
#define maximize(a, x) a = std::max(a, x)

using ll  = long long;
int const inf = 1<<29;

int N, M;

vector<pair<int, double>> dag[30];

int main() {

  cin >> N >> M; 

  rep(i, M) {
    int a, b; double c;
    cin >> a >> b >> c; c /= 100;
    dag[a].emplace_back(b, c);
  }

  vector<double> inTarget;

  queue<pair<int, double>> q;
  q.emplace(0, 1.0);

  while(!q.empty()) {
    auto p = q.front(); q.pop();
    int curr = p.first;
    double prob = p.second;

    rep(i, dag[curr].size()) {
      int tar = dag[curr][i].first;
      double trans = dag[curr][i].second;
      if(tar == N-1) {
        inTarget.push_back(prob * trans);
      }
      else {
        q.emplace(tar, prob * trans);
      }
    }
  }

  int n = inTarget.size();
  double res = 0.0;
  REP(S, 1, 1<<n) {
    int sign = __builtin_popcount(S) % 2 ? 1 : -1;
    double sum = sign;
    rep(i, n) {
      if(S >> i & 1) {
        sum *= inTarget[i];
      }
    }
    res += sum;
  }

  printf("%.10f\n", res);

  return 0;
}
0