Submission #273999

# Submission time Handle Problem Language Result Execution time Memory
273999 2020-08-19T08:08:16 Z Fasho Fishing Game (RMI19_fishing) C++14
0 / 100
529 ms 524292 KB
#include <bits/stdc++.h>
#define N 301
#define ll long long int
#define fo(i,x,y)	for(int i=x;i<=y;i++)
#define fs(ar,n) fo(i,1,n) cin>>ar[i]
#define sp " "
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll> 
#define mod 1000000007
using namespace std;

ll n,m,ar[N],sum,t,tut1[N],tut2[N],dp[201][201][201][4];

ll add(ll x,ll y)
{
	x%=mod;
	y%=mod;
	return (((x+y)%mod)+mod)%mod;
}
ll carp(ll x,ll y)
{
	x%=mod;
	y%=mod;
	return (((x*y)%mod)+mod)%mod;
}

ll f(ll a,ll b,ll c,ll x)
{

	if(dp[a][b][c][x])
		return dp[a][b][c][x];
	if(!a && !b && !c)
		return dp[a][b][c][x]=1;
	if(x==1)
	{
		ll top=0;
		if(!a && !b)
			return dp[a][b][c][x]=f(a,b,c,2);
		if(a)
			top=add(top,carp(f(a-1,b,c,2),a));
		if(b)
			top=add(top,carp(f(a,b-1,c+1,2),b));
		return dp[a][b][c][x]=top;
	}
	if(x==2)
	{
		ll top=0;
		if(!a && !c)
			return dp[a][b][c][x]=f(a,b,c,3);
		if(c)
			top=add(top,carp(f(a,b,c-1,3),c));
		if(a)
			top=add(top,carp(f(a-1,b+1,c,3),a));
		// cout<<a<<sp<<b<<sp<<c<<sp<<top<<endl;
		return dp[a][b][c][x]=top;
	}
	if(x==3)
	{
		ll top=0;
		if(!b && !c)
			return dp[a][b][c][x]=f(a,b,c,1);
		if(b)
			top=add(top,carp(f(a,b-1,c,1),b));
		if(c)
			top=add(top,carp(f(a+1,b,c-1,1),c));
		return dp[a][b][c][x]=top;
	}
	return 1;

}

int main()
{
	fast;
	cin>>n>>t;
	while(t--)
	{
		ll a=0,b=0,c=0;
		fo(i,1,n*3)
			tut1[i]=0,tut2[i]=0;
		fo(i,1,3)
			fo(j,1,n*2)
				{
					ll x;
					cin>>x;
					// cout<<x<<endl;
					if(tut1[x])
					{
						tut2[x]=i;
						if(tut1[x]==i)
							continue;
						if(tut1[x]==1)
						{
							if(i==2)
								a++;
							else
								b++;
						}
						else
							c++;
					}
					else
						tut1[x]=i;
				}
		// cout<<a<<sp<<b<<sp<<c<<endl;
			cout<<f(a,b,c,1)<<endl;
	}

} 
# Verdict Execution time Memory Grader output
1 Runtime error 505 ms 524292 KB Execution killed with signal 9
2 Runtime error 459 ms 524292 KB Execution killed with signal 9
3 Runtime error 474 ms 524292 KB Execution killed with signal 9
4 Runtime error 484 ms 524292 KB Execution killed with signal 9
5 Runtime error 522 ms 524292 KB Execution killed with signal 9
6 Runtime error 529 ms 524292 KB Execution killed with signal 9
7 Runtime error 492 ms 524292 KB Execution killed with signal 9
8 Runtime error 481 ms 524288 KB Execution killed with signal 9
9 Runtime error 459 ms 524288 KB Execution killed with signal 9
10 Runtime error 490 ms 524292 KB Execution killed with signal 9