結果

問題 No.108 トリプルカードコンプ
ユーザー 37zigen37zigen
提出日時 2016-05-19 10:10:40
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,631 bytes
コンパイル時間 2,978 ms
コンパイル使用メモリ 79,176 KB
実行使用メモリ 102,024 KB
最終ジャッジ日時 2024-04-15 23:09:21
合計ジャッジ時間 11,163 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
46,952 KB
testcase_01 AC 142 ms
42,728 KB
testcase_02 AC 178 ms
45,408 KB
testcase_03 AC 138 ms
41,964 KB
testcase_04 AC 135 ms
41,964 KB
testcase_05 AC 140 ms
42,160 KB
testcase_06 AC 137 ms
42,236 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];

		int sum_0=0;//0枚のカードの種類数
		int sum_1=0;//1枚のカードの種類数
		int sum_2=0;//2枚のカードの種類数
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
			if(A[i]==0)sum_0++;
			else if(A[i]==1)sum_1++;
			else if(A[i]==2)sum_2++;
		}
		//p[i][j][k]=0枚のカードがi種類,1枚のカードがj種類,2枚のカードがk種類の確率。
		double[][][] from=new double[N+1][N+1][N+1];
		double[][][] to=new double[N+1][N+1][N+1];
		from[sum_0][sum_1][sum_2]=1;
		//e:期待値
		double e=0;
		for(int t=1;t<=3000;t++){
			for(int i=0;i<N+1;i++){
				for(int j=0;j+i<N+1;j++){
					for(int k=0;k+i+j<N+1;k++){
						//						tr(from);
						//						System.out.println();
						to[i][j][k]+=from[i][j][k]*((double)(N-i-j-k)/(double)N);
						if(i>=1){
							to[i-1][j+1][k]+=from[i][j][k]*((double)i/(double)N);
						}
						if(j>=1){
							to[i][j-1][k+1]+=from[i][j][k]*((double)j/(double)N);
						}
						if(k>=1){
							if(i==0&&j==0&&k==1)
								e+=t*from[i][j][k]*((double)k/(double)N);
							to[i][j][k-1]+=from[i][j][k]*((double)k/(double)N);
						}
					}
				}
			}
			from=to;double[][][] d=new double[N+1][N+1][N+1];
			to=d;
		}
		System.out.println(e);
	}
	void tr(double[][][] p){
		int n=p.length;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					System.out.println(i+" "+j+" "+k+" "+p[i][j][k]);
				}
			}
		}
	}
}
0