Submission #463699

# Submission time Handle Problem Language Result Execution time Memory
463699 2021-08-11T14:07:57 Z mosiashvililuka Fishing Game (RMI19_fishing) C++17
100 / 100
1168 ms 108888 KB
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,mod=1000000007LL,dp[303][303][303],tes,t,II,k,kk,f[8],bl[603];
void rec(long long q, bool bo){
	if(f[1]<0||f[2]<0||f[3]<0) return;
	long long ZX=zx;
	if(q==4){
		if(bo==0) return;
		dp[i][j][k]+=dp[f[1]][f[2]][f[3]]*zx;dp[i][j][k]%=mod;
		return;
	}
	if(q==1){
		if(f[1]+f[3]==0){
			rec(q+1,bo);
			zx=ZX;
			return;
		}
		zx*=f[1];zx%=mod;
		f[1]--;
		rec(q+1,1);
		zx=ZX;
		f[1]++;
		//
		zx*=f[3];zx%=mod;
		f[3]--;f[2]++;
		rec(q+1,bo);
		zx=ZX;
		f[3]++;f[2]--;
		return;
	}
	if(q==2){
		if(f[1]+f[2]==0){
			rec(q+1,bo);
			zx=ZX;
			return;
		}
		zx*=f[1];zx%=mod;
		f[1]--;f[3]++;
		rec(q+1,bo);
		zx=ZX;
		f[1]++;f[3]--;
		//
		zx*=f[2];zx%=mod;
		f[2]--;
		rec(q+1,1);
		zx=ZX;
		f[2]++;
		return;
	}
	if(q==3){
		if(f[2]+f[3]==0){
			rec(q+1,bo);
			zx=ZX;
			return;
		}
		zx*=f[2];zx%=mod;
		f[2]--;f[1]++;
		rec(q+1,bo);
		zx=ZX;
		f[2]++;f[1]--;
		//
		zx*=f[3];zx%=mod;
		f[3]--;
		rec(q+1,1);
		zx=ZX;
		f[3]++;
		return;
	}
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>tes;
	dp[0][0][0]=1;
	for(II=1; II<=300; II++){
		for(i=0; i<=II; i++){
			for(j=0; j<=II-i; j++){
				k=II-i-j;
				f[1]=i;f[2]=j;f[3]=k;zx=1;
				rec(1,0);
			}
		}
	}
	for(t=1; t<=tes; t++){
		f[1]=0;f[2]=0;f[3]=0;
		for(i=0; i<=a*6; i++){
			bl[i]=0;
		}
		for(i=1; i<=3; i++){
			for(j=1; j<=2*a; j++){
				cin>>c;
				if(bl[c]==0){
					bl[c]=i;
				}else{
					if(bl[c]==1&&i==2){
						f[1]++;
					}
					if(bl[c]==2&&i==3){
						f[2]++;
					}
					if(bl[c]==1&&i==3){
						f[3]++;
					}
				}
			}
		}
		cout<<dp[f[1]][f[2]][f[3]]<<endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1096 ms 108888 KB Output is correct
2 Correct 1061 ms 108740 KB Output is correct
3 Correct 1102 ms 108796 KB Output is correct
4 Correct 1035 ms 108760 KB Output is correct
5 Correct 1069 ms 108816 KB Output is correct
6 Correct 1053 ms 108788 KB Output is correct
7 Correct 1008 ms 108868 KB Output is correct
8 Correct 924 ms 108880 KB Output is correct
9 Correct 1033 ms 108752 KB Output is correct
10 Correct 1168 ms 108724 KB Output is correct