結果

問題 No.662 スロットマシーン
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-01-18 05:56:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,778 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 71,680 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 23:10:28
合計ジャッジ時間 1,621 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<string>
#include<map>
#include<iostream>
#include<string.h>

const int LIMIT=5000;
const int M=5;

std::map<std::string,int> strToNo;
long long int ansC[M]={0,0,0,0,0};
long long int counts[3][M][M][M];
double ans=0;
int as[3][3];
int noToCoin[M];
int cols[3][LIMIT];
int colSize[3];

void f(long long int p){
	int a=as[0][0];
	if((a==as[0][1])&&(a==as[0][2])){
		ansC[a]+=p;
		ans+=p*noToCoin[a];
	}
	a=as[1][0];
	if((a==as[1][1])&&(a==as[1][2])){
		ansC[a]+=p;
		ans+=p*noToCoin[a];
	}
	a=as[2][0];
	if((a==as[2][1])&&(a==as[2][2])){
		ansC[a]+=p;
		ans+=p*noToCoin[a];
	}
	a=as[0][0];
	if((a==as[1][1])&&(a==as[2][2])){
		ansC[a]+=p;
		ans+=p*noToCoin[a];
	}
	a=as[2][0];
	if((a==as[1][1])&&(a==as[0][2])){
		ansC[a]+=p;
		ans+=p*noToCoin[a];
	}
}
void read(int col){
	int n;
	scanf("%d",&n);
	colSize[col]=n;
	for(int i=0;i<n;i++){
		std::string str;
		std::cin>>str;
		cols[col][i]=strToNo[str];
	}
}
void regist(int no){
	int c=colSize[no];
	for(int i=0;i<c;i++){
		int a1=cols[no][i];
		int a2=cols[no][(i+1)%c];
		int a3=cols[no][(i+2)%c];
		counts[no][a1][a2][a3]++;
	}
}

void search(int deep,long long int perm){
	if(deep==3){
		f(perm);
	}else{
		for(int i=0;i<M;i++){
			as[0][deep]=i;
			for(int j=0;j<M;j++){
				as[1][deep]=j;
				for(int k=0;k<M;k++){
					as[2][deep]=k;
					search(deep+1,perm*counts[deep][i][j][k]);
				}	
			}
		}
	}
}

int main(){
	memset(counts,0,sizeof(counts));
	for(int i=0;i<M;i++){
		std::string str;
		int coin;
		std::cin>>str>>coin;
		noToCoin[i]=coin;
		strToNo[str]=i;
	}
	read(0);
	read(1);
	read(2);
	regist(0);
	regist(1);
	regist(2);
	search(0,1);
	
	double all=colSize[0];
	all*=colSize[1];
	all*=colSize[2];
	printf("%lf\n",ans/all);
	for(int i=0;i<M;i++){
		std::cout<<ansC[i]<<std::endl;
	}
}
0