結果

問題 No.298 話の伝達
ユーザー ぴろずぴろず
提出日時 2015-11-08 18:25:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 765 ms / 5,000 ms
コード長 1,062 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 59,504 KB
最終ジャッジ日時 2023-10-11 15:20:33
合計ジャッジ時間 8,580 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,688 KB
testcase_01 AC 130 ms
55,636 KB
testcase_02 AC 130 ms
55,708 KB
testcase_03 AC 129 ms
55,836 KB
testcase_04 AC 130 ms
55,396 KB
testcase_05 AC 292 ms
58,268 KB
testcase_06 AC 137 ms
55,844 KB
testcase_07 AC 128 ms
55,864 KB
testcase_08 AC 127 ms
55,688 KB
testcase_09 AC 140 ms
55,964 KB
testcase_10 AC 160 ms
57,832 KB
testcase_11 AC 319 ms
58,544 KB
testcase_12 AC 234 ms
58,304 KB
testcase_13 AC 352 ms
58,676 KB
testcase_14 AC 220 ms
55,452 KB
testcase_15 AC 129 ms
55,684 KB
testcase_16 AC 765 ms
59,504 KB
testcase_17 AC 175 ms
58,188 KB
testcase_18 AC 302 ms
58,296 KB
testcase_19 AC 129 ms
55,876 KB
testcase_20 AC 454 ms
59,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no298;

import java.util.ArrayList;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}

	int n;
	int m;
	ArrayList<Edge>[] g;
	@SuppressWarnings("unchecked")
	public void solve() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		g = new ArrayList[n];
		for(int i=0;i<n;i++) {
			g[i] = new ArrayList<>();
		}
		for(int i=0;i<m;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			double c = sc.nextInt() / 100D;
			g[b].add(new Edge(a,c));
		}
		double ans = 0;
		for(int i=(1<<n-1)+1;i<1<<n;i+=2) {
			double p = 1;
			for(int v=1;v<n;v++) {
				double q = 1;
				for(Edge e:g[v]) {
					int u = e.to;
					if ((i >> u & 1) == 1) {
						q *= (1 - e.p);
					}
				}
				p *= (i >> v & 1) == 0 ? q : (1 - q);
			}
			ans += p;
		}
		System.out.println(ans);
	}

	static class Edge {
		int to;
		double p;
		public Edge(int to,double p) {
			this.to = to;
			this.p = p;
		}
		public String toString() {
			return "[" + to + "," + p + "]";
		}
	}
}
0