Submission #200059

# Submission time Handle Problem Language Result Execution time Memory
200059 2020-02-05T07:49:35 Z guangxuan Fishing Game (RMI19_fishing) C++14
100 / 100
388 ms 107256 KB
#include <bits/stdc++.h>
const long long MOD=1e9+7;
using namespace std;

int mm[301][301][301];

int dp(int x,int y,int z){ // ab,bc,ca
	if(mm[x][y][z]!=-1)return mm[x][y][z];
	if(x==0&&y==0&&z==0)return mm[x][y][z]=1;
	mm[x][y][z]=0;
	//printf("STATE %d %d %d\n",x,y,z);
	for(int xk=0;xk<2;xk++){
		int x2=x,y2=y,z2=z,mult=1;
		if(x2+z2!=0){
			if(xk){
				mult*=x2;
				x2--;
			}
			else{
				mult*=z2;
				z2--,y2++;
			}
		}
		else if(xk)continue;//do nothing!
		if(x2<0||y2<0||z2<0)continue;
		for(int yk=0;yk<2;yk++){
			int x3=x2,y3=y2,z3=z2,mult2=mult;
			if(x3+y3!=0){
				if(yk){
					mult2*=y3;
					y3--;
				}
				else{
					mult2*=x3;
					x3--,z3++;
				}
			}
			else if(yk)continue;//do nothing!
			if(x3<0||y3<0||z3<0)continue;
			for(int zk=0;zk<2;zk++){
				int x4=x3,y4=y3,z4=z3,mult3=mult2;
				if(y4+z4!=0){
					if(zk){
						mult3*=z4;
						z4--;
					}
					else{
						mult3*=y4;
						y4--,x4++;
					}
				}
				else if(zk)continue;//do nothing!
				if(x4<0||y4<0||z4<0)continue;
				if((xk||yk||zk)==0)continue;
				//printf("TRANS %d %d %d %lld\n",x4,y4,z4,mult);
				mm[x][y][z]=((long long)mm[x][y][z]+(long long)dp(x4,y4,z4)*mult3)%MOD;
			}
		}
	}
	return mm[x][y][z];
}

int hascard[3][300];

int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	while(t--){
		memset(mm,-1,sizeof mm);
		memset(hascard,0,sizeof hascard);
		int x=0,y=0,z=0;
		for(int p=0;p<3;p++){
			for(int i=0;i<n*2;i++){
				int card;
				scanf("%d",&card);
				card--;
				hascard[p][card]=1;
			}
		}
		for(int i=0;i<3*n;i++){
			x+=hascard[0][i]&&hascard[1][i];
			y+=hascard[1][i]&&hascard[2][i];
			z+=hascard[2][i]&&hascard[0][i];
		}
		printf("%d\n",dp(x,y,z));
	}
}

Compilation message

fishing.cpp: In function 'int main()':
fishing.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&t);
  ~~~~~^~~~~~~~~~~~~~
fishing.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&card);
     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 85 ms 107000 KB Output is correct
2 Correct 116 ms 107128 KB Output is correct
3 Correct 112 ms 107128 KB Output is correct
4 Correct 113 ms 107128 KB Output is correct
5 Correct 214 ms 107156 KB Output is correct
6 Correct 231 ms 107132 KB Output is correct
7 Correct 269 ms 107132 KB Output is correct
8 Correct 285 ms 107256 KB Output is correct
9 Correct 339 ms 107128 KB Output is correct
10 Correct 388 ms 107128 KB Output is correct