結果

問題 No.298 話の伝達
ユーザー GrenacheGrenache
提出日時 2015-11-09 10:55:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,084 ms / 5,000 ms
コード長 1,756 bytes
コンパイル時間 4,985 ms
コンパイル使用メモリ 75,868 KB
実行使用メモリ 59,960 KB
最終ジャッジ日時 2023-10-11 15:25:25
合計ジャッジ時間 11,240 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
56,116 KB
testcase_01 AC 132 ms
55,992 KB
testcase_02 AC 132 ms
55,852 KB
testcase_03 AC 133 ms
55,832 KB
testcase_04 AC 131 ms
55,972 KB
testcase_05 AC 410 ms
59,284 KB
testcase_06 AC 143 ms
56,164 KB
testcase_07 AC 134 ms
55,960 KB
testcase_08 AC 131 ms
55,712 KB
testcase_09 AC 144 ms
56,264 KB
testcase_10 AC 195 ms
59,352 KB
testcase_11 AC 359 ms
59,168 KB
testcase_12 AC 266 ms
59,572 KB
testcase_13 AC 454 ms
59,516 KB
testcase_14 AC 268 ms
58,792 KB
testcase_15 AC 132 ms
54,052 KB
testcase_16 AC 1,084 ms
59,960 KB
testcase_17 AC 195 ms
58,260 KB
testcase_18 AC 364 ms
58,916 KB
testcase_19 AC 133 ms
55,748 KB
testcase_20 AC 648 ms
59,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main_yukicoder298_1 {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        List<List<Edge>> edges = new ArrayList<List<Edge>>();
        for (int i = 0; i < n; i++) {
        	edges.add(new ArrayList<Edge>());
        }
        
        for (int i = 0; i < m; i++) {
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	int c = sc.nextInt();
        	
        	edges.get(b).add(new Edge(a, b, c));
        }

        int bit = 0, mask = 0;
        bit |= 0x1 << 0;
        mask |= 0x1 << 0;
        bit |= 0x1 << n - 1;
        mask |= 0x1 << n - 1;

        double ret = 0;
        for (int i = 0; i < 0x1 << n; i++) {
        	if ((i & mask) != bit) {
        		continue;
        	}

        	boolean[] yuki = new boolean[n];
        	for (int j = 0; j < n; j++) {
        		if ((i & 0x1 << j) != 0) {
        			yuki[j] = true;
        		}
        	}

        	double tmp = 1.0;
        	for (int j = 1; j < n; j++) {
        		double tmp2 = 1.0;
        		for (Edge from : edges.get(j)) {
        			if (yuki[from.a]) {
        				tmp2 *= (double)(100 - from.c) / 100;
        			}
        		}
        		
        		if (yuki[j]) {
        			tmp *= 1.0 - tmp2;
        		} else {
        			tmp *= tmp2;
        		}
        	}
        	
        	ret += tmp;
        }
        
        System.out.printf("%.7f\n", ret);
        
        sc.close();
    }
    
    private static class Edge {
    	int a;
//    	int b;
    	int c;
    	
    	Edge(int a, int b, int c) {
    		this.a = a;
//    		this.b = b;
    		this.c = c;
    	}
    }
}
0